Introduction

Hi, my name is Andrew Trask. I am currently a PhD student at the University of Oxford studying Deep Learning for Natural Language Processing. Natural Language Processing is the field that studies human language and today we’re going to be talking about Sentiment Classification, or the classification of whether or not a section of human-generated text is positive or negative (i.e., happy or sad). Deep Learning, as I’m sure you’re coming to understand, is a set of tools (neural networks) used to take what we “know”, and predict what we what we “want to know”. In this case, we “know” a paragraph of text generated from a human, and we “want to know” whether or not it has positive or negative sentiment. Our goal is to build a neural network that can make this prediction.

What you will learn along the way - "Framing a Problem"

What this tutorial is really about is "framing a problem" so that a neural network can be successful in solving it. Sentiment is a great example because neural networks don't take raw text as input, they take numbers! We have to consider how to efficiently transform our text into numbers so that our network can learn a valuable underlying pattern. I can't stress enough how important this skillset will be to your career. Frameworks (like TensorFlow) will handle backpropagation, gradients, and error measures for you, but "framing the problem" is up to you, the scientist, and if it's not done correctly, your networks will spend forever searching for correlation between your two datasets (and they might never find it).

What You Should Already Know

I am assuming you already know about neural networks, forward and back-propagation, stochastic gradient descent, mean squared error, and train/test splits from previous lessons.

It Starts with a Dataset

Neural networks, by themselves, cannot do anything. All a neural network really does is search for direct or indirect correlation between two datasets. So, in order for a neural network to learn anything, we have to present it with two, meaningful datasets. The first dataset must represent what we “know” and the second dataset must represent what we “want to know”, or what we want the neural network to be able to tell us. As the network trains, it’s going to search for correlation between these two datasets, so that eventually it can take one and predict the other. Let me show you what I mean with our example sentiment dataset.


In [1]:
def pretty_print_review_and_label(i):
    print(labels[i] + "\t:\t" + reviews[i][:80] + "...")

g = open('reviews.txt','r')
reviews = list(map(lambda x:x[:-1],g.readlines()))
g.close()

g = open('labels.txt','r')
labels = list(map(lambda x:x[:-1].upper(),g.readlines()))
g.close()

In the cell above, I have loaded two datasets. The first dataset "reviews" is a list of 25,000 movie reviews that people wrote about various movies. The second dataset is a list of whether or not each review is a “positive” review or “negative” review.


In [2]:
reviews[0]


Out[2]:
'bromwell high is a cartoon comedy . it ran at the same time as some other programs about school life  such as  teachers  . my   years in the teaching profession lead me to believe that bromwell high  s satire is much closer to reality than is  teachers  . the scramble to survive financially  the insightful students who can see right through their pathetic teachers  pomp  the pettiness of the whole situation  all remind me of the schools i knew and their students . when i saw the episode in which a student repeatedly tried to burn down the school  i immediately recalled . . . . . . . . . at . . . . . . . . . . high . a classic line inspector i  m here to sack one of your teachers . student welcome to bromwell high . i expect that many adults of my age think that bromwell high is far fetched . what a pity that it isn  t   '

In [3]:
labels[0]


Out[3]:
'POSITIVE'

I want you to pretend that you’re a neural network for a moment. Consider a few examples from the two datasets below. Do you see any correlation between these two datasets?


In [4]:
print("labels.txt \t : \t reviews.txt\n")
pretty_print_review_and_label(2137)
pretty_print_review_and_label(12816)
pretty_print_review_and_label(6267)
pretty_print_review_and_label(21934)
pretty_print_review_and_label(5297)
pretty_print_review_and_label(4998)


labels.txt 	 : 	 reviews.txt

NEGATIVE	:	this movie is terrible but it has some good effects .  ...
POSITIVE	:	adrian pasdar is excellent is this film . he makes a fascinating woman .  ...
NEGATIVE	:	comment this movie is impossible . is terrible  very improbable  bad interpretat...
POSITIVE	:	excellent episode movie ala pulp fiction .  days   suicides . it doesnt get more...
NEGATIVE	:	if you haven  t seen this  it  s terrible . it is pure trash . i saw this about ...
POSITIVE	:	this schiffer guy is a real genius  the movie is of excellent quality and both e...

Well, let’s consider several different granularities. At the paragraph level, no two paragraphs are the same, so there can be no “correlation” per-say. You have to see two things occur at the same time more than once in order for there to be considered “correlation”. What about at the character level? I’m guessing the letter “b” is used just as much in positive reviews as it is in negative reviews. How about word level? Ah, I think there's some correlation between the words in these reviews and whether or not the review is positive or negative.


In [5]:
from collections import Counter

In [6]:
positive_counts = Counter()
negative_counts = Counter()
total_counts = Counter()

for i in range(len(reviews)):
    if(labels[i] == 'POSITIVE'):
        for word in reviews[i].split(" "):
            positive_counts[word] += 1
            total_counts[word] += 1
    else:
        for word in reviews[i].split(" "):
            negative_counts[word] += 1
            total_counts[word] += 1
            
pos_neg_ratios = Counter()

for term,cnt in list(total_counts.most_common()):
    if(cnt > 10):
        pos_neg_ratio = positive_counts[term] / float(negative_counts[term]+1)
        pos_neg_ratios[term] = pos_neg_ratio

for word,ratio in pos_neg_ratios.most_common():
    if(ratio > 1):
        pos_neg_ratios[word] = np.log(ratio)
    else:
        pos_neg_ratios[word] = -np.log((1 / (ratio+0.01)))


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-25875bd2c637> in <module>()
     22 for word,ratio in pos_neg_ratios.most_common():
     23     if(ratio > 1):
---> 24         pos_neg_ratios[word] = np.log(ratio)
     25     else:
     26         pos_neg_ratios[word] = -np.log((1 / (ratio+0.01)))

NameError: name 'np' is not defined

In [169]:
# words most frequently seen in a review with a "POSITIVE" label
pos_neg_ratios.most_common()


Out[169]:
[('edie', 4.6913478822291435),
 ('antwone', 4.4773368144782069),
 ('din', 4.4067192472642533),
 ('gunga', 4.1896547420264252),
 ('goldsworthy', 4.1743872698956368),
 ('yokai', 4.0943445622221004),
 ('gypo', 4.0943445622221004),
 ('paulie', 4.0775374439057197),
 ('visconti', 3.9318256327243257),
 ('flavia', 3.9318256327243257),
 ('blandings', 3.8712010109078911),
 ('kells', 3.8712010109078911),
 ('brashear', 3.8501476017100584),
 ('gino', 3.8286413964890951),
 ('deathtrap', 3.8066624897703196),
 ('harilal', 3.713572066704308),
 ('panahi', 3.713572066704308),
 ('ossessione', 3.6635616461296463),
 ('tsui', 3.6375861597263857),
 ('caruso', 3.6375861597263857),
 ('ahmad', 3.6109179126442243),
 ('sabu', 3.6109179126442243),
 ('khouri', 3.5835189384561099),
 ('dominick', 3.5835189384561099),
 ('aweigh', 3.5553480614894135),
 ('mj', 3.5553480614894135),
 ('mcintire', 3.5263605246161616),
 ('kriemhild', 3.5263605246161616),
 ('newcombe', 3.4965075614664802),
 ('daisies', 3.4965075614664802),
 ('blackie', 3.4965075614664802),
 ('trelkovsky', 3.4657359027997265),
 ('kei', 3.4657359027997265),
 ('hilliard', 3.4339872044851463),
 ('jaffar', 3.4339872044851463),
 ('gundam', 3.4231762883809305),
 ('bathsheba', 3.4011973816621555),
 ('sheeta', 3.4011973816621555),
 ('pazu', 3.4011973816621555),
 ('krell', 3.4011973816621555),
 ('offside', 3.4011973816621555),
 ('venoms', 3.3672958299864741),
 ('fineman', 3.3672958299864741),
 ('paine', 3.3322045101752038),
 ('pimlico', 3.3322045101752038),
 ('ronny', 3.3322045101752038),
 ('ranma', 3.3322045101752038),
 ('abhay', 3.2958368660043291),
 ('iturbi', 3.2771447329921766),
 ('pym', 3.2580965380214821),
 ('kipling', 3.2580965380214821),
 ('scalise', 3.2188758248682006),
 ('gabe', 3.2188758248682006),
 ('kelso', 3.2188758248682006),
 ('milverton', 3.2188758248682006),
 ('audiard', 3.2188758248682006),
 ('grisby', 3.1780538303479458),
 ('moonwalker', 3.1780538303479458),
 ('xica', 3.1780538303479458),
 ('mukhsin', 3.1780538303479458),
 ('feinstone', 3.1780538303479458),
 ('giovanna', 3.1780538303479458),
 ('felix', 3.1527360223636558),
 ('jannings', 3.1354942159291497),
 ('togar', 3.1354942159291497),
 ('chikatilo', 3.1354942159291497),
 ('heaton', 3.1354942159291497),
 ('luzhin', 3.1135153092103742),
 ('miklos', 3.0910424533583161),
 ('soha', 3.0910424533583161),
 ('leonora', 3.0910424533583161),
 ('matador', 3.0910424533583161),
 ('fanfan', 3.0910424533583161),
 ('matuschek', 3.0910424533583161),
 ('desdemona', 3.0910424533583161),
 ('pidgeon', 3.0910424533583161),
 ('philo', 3.068052935133617),
 ('lindy', 3.044522437723423),
 ('joss', 3.044522437723423),
 ('reda', 3.044522437723423),
 ('gauri', 3.044522437723423),
 ('microfilm', 3.044522437723423),
 ('maradona', 3.044522437723423),
 ('firemen', 3.044522437723423),
 ('bjm', 3.044522437723423),
 ('capote', 3.0122615755052013),
 ('fido', 3.0081547935525483),
 ('mcintyre', 2.9957322735539909),
 ('quibble', 2.9957322735539909),
 ('coonskin', 2.9957322735539909),
 ('emory', 2.9957322735539909),
 ('prote', 2.9957322735539909),
 ('carrre', 2.9957322735539909),
 ('siegfried', 2.9957322735539909),
 ('coe', 2.9957322735539909),
 ('excellently', 2.9789251552376097),
 ('clutter', 2.9704144655697009),
 ('baloo', 2.9444389791664403),
 ('railly', 2.9444389791664403),
 ('ackland', 2.9444389791664403),
 ('magnus', 2.9444389791664403),
 ('versatility', 2.9444389791664403),
 ('burakov', 2.9444389791664403),
 ('malfique', 2.9444389791664403),
 ('digicorp', 2.9444389791664403),
 ('schlesinger', 2.9444389791664403),
 ('anchors', 2.9444389791664403),
 ('hillyer', 2.9444389791664403),
 ('flippen', 2.9444389791664403),
 ('petiot', 2.9444389791664403),
 ('vance', 2.9444389791664403),
 ('knockout', 2.9444389791664403),
 ('ferdie', 2.9444389791664403),
 ('pinjar', 2.9444389791664403),
 ('pakeezah', 2.9444389791664403),
 ('rvd', 2.9444389791664403),
 ('kolchak', 2.9311937524164198),
 ('hayworth', 2.9267394020670396),
 ('deanna', 2.9267394020670396),
 ('lando', 2.8903717578961645),
 ('hobson', 2.8903717578961645),
 ('pollak', 2.8903717578961645),
 ('falco', 2.8903717578961645),
 ('iphigenia', 2.8903717578961645),
 ('geer', 2.8903717578961645),
 ('burgade', 2.8903717578961645),
 ('volckman', 2.8903717578961645),
 ('pappas', 2.8903717578961645),
 ('iek', 2.8903717578961645),
 ('guerrero', 2.8903717578961645),
 ('hoechlin', 2.8903717578961645),
 ('korda', 2.8622008809294686),
 ('sammo', 2.8526314299133175),
 ('jeon', 2.8332133440562162),
 ('laputa', 2.8332133440562162),
 ('biko', 2.8332133440562162),
 ('callahan', 2.8332133440562162),
 ('nighy', 2.8332133440562162),
 ('orked', 2.8332133440562162),
 ('nagra', 2.8332133440562162),
 ('sox', 2.8332133440562162),
 ('peralta', 2.8332133440562162),
 ('toughness', 2.8332133440562162),
 ('naudet', 2.8332133440562162),
 ('jacknife', 2.8332133440562162),
 ('kralik', 2.8332133440562162),
 ('cdric', 2.8332133440562162),
 ('beckett', 2.8332133440562162),
 ('hewlett', 2.8332133440562162),
 ('polanski', 2.8233610476132043),
 ('alvin', 2.8183982582710754),
 ('matthau', 2.8067217286092401),
 ('aiello', 2.8033603809065348),
 ('natalia', 2.7725887222397811),
 ('janos', 2.7725887222397811),
 ('gaiman', 2.7725887222397811),
 ('coulouris', 2.7725887222397811),
 ('bedknobs', 2.7725887222397811),
 ('rotj', 2.7725887222397811),
 ('hulce', 2.7725887222397811),
 ('duffell', 2.7725887222397811),
 ('firefighter', 2.7725887222397811),
 ('macready', 2.7725887222397811),
 ('delpy', 2.7725887222397811),
 ('mathieu', 2.7725887222397811),
 ('endor', 2.7725887222397811),
 ('bombshells', 2.7725887222397811),
 ('antz', 2.7725887222397811),
 ('santos', 2.7725887222397811),
 ('yvaine', 2.7725887222397811),
 ('gackt', 2.7515353130419489),
 ('myrtle', 2.7515353130419489),
 ('adele', 2.7515353130419489),
 ('bake', 2.7408400239252009),
 ('gilliam', 2.7245795030534206),
 ('johnnie', 2.7080502011022101),
 ('egon', 2.7080502011022101),
 ('valette', 2.7080502011022101),
 ('baton', 2.7080502011022101),
 ('kiley', 2.7080502011022101),
 ('cheh', 2.7080502011022101),
 ('hilda', 2.7080502011022101),
 ('grasshoppers', 2.7080502011022101),
 ('lanisha', 2.7080502011022101),
 ('goines', 2.7080502011022101),
 ('gannon', 2.7080502011022101),
 ('shintaro', 2.7080502011022101),
 ('rotoscoped', 2.7080502011022101),
 ('doktor', 2.7080502011022101),
 ('silberling', 2.7080502011022101),
 ('lian', 2.7080502011022101),
 ('parador', 2.7080502011022101),
 ('burman', 2.7080502011022101),
 ('mcanally', 2.7080502011022101),
 ('cognac', 2.7080502011022101),
 ('oro', 2.7080502011022101),
 ('soutendijk', 2.7080502011022101),
 ('gunbuster', 2.7080502011022101),
 ('calamai', 2.7080502011022101),
 ('ballantine', 2.7080502011022101),
 ('aviv', 2.7080502011022101),
 ('hickock', 2.7080502011022101),
 ('uld', 2.7080502011022101),
 ('eustache', 2.7080502011022101),
 ('bernsen', 2.7080502011022101),
 ('schildkraut', 2.7080502011022101),
 ('karas', 2.7080502011022101),
 ('ashraf', 2.7080502011022101),
 ('victoria', 2.6810215287142909),
 ('beery', 2.6741486494265287),
 ('conroy', 2.6741486494265287),
 ('dench', 2.6741486494265287),
 ('partition', 2.6741486494265287),
 ('chavez', 2.6672282065819548),
 ('ratso', 2.653241964607215),
 ('kabei', 2.6390573296152584),
 ('duprez', 2.6390573296152584),
 ('melancholic', 2.6390573296152584),
 ('kulkarni', 2.6390573296152584),
 ('bathhouse', 2.6390573296152584),
 ('beek', 2.6390573296152584),
 ('hickam', 2.6390573296152584),
 ('intricately', 2.6390573296152584),
 ('harriet', 2.6390573296152584),
 ('cartwrights', 2.6390573296152584),
 ('emy', 2.6390573296152584),
 ('megs', 2.6390573296152584),
 ('pang', 2.6390573296152584),
 ('tulip', 2.6390573296152584),
 ('atoz', 2.6390573296152584),
 ('fetisov', 2.6390573296152584),
 ('laine', 2.6390573296152584),
 ('pilgrimage', 2.6390573296152584),
 ('treaty', 2.6390573296152584),
 ('ishwar', 2.6390573296152584),
 ('danelia', 2.6390573296152584),
 ('scrat', 2.6390573296152584),
 ('ingram', 2.6390573296152584),
 ('cb', 2.6390573296152584),
 ('embezzler', 2.6390573296152584),
 ('gardenia', 2.6390573296152584),
 ('gialli', 2.6390573296152584),
 ('rien', 2.6390573296152584),
 ('dev', 2.6026896854443837),
 ('mildred', 2.6026896854443837),
 ('fricker', 2.6026896854443837),
 ('emil', 2.6026896854443837),
 ('katsu', 2.6026896854443837),
 ('ultimatum', 2.6026896854443837),
 ('sputnik', 2.5649493574615367),
 ('eglantine', 2.5649493574615367),
 ('oakie', 2.5649493574615367),
 ('yelnats', 2.5649493574615367),
 ('gabriella', 2.5649493574615367),
 ('bahrain', 2.5649493574615367),
 ('autograph', 2.5649493574615367),
 ('odysseus', 2.5649493574615367),
 ('cynics', 2.5649493574615367),
 ('adjani', 2.5649493574615367),
 ('mcdoakes', 2.5649493574615367),
 ('luchino', 2.5649493574615367),
 ('nibelungen', 2.5649493574615367),
 ('saura', 2.5649493574615367),
 ('freebird', 2.5649493574615367),
 ('boop', 2.5649493574615367),
 ('brownstone', 2.5649493574615367),
 ('dola', 2.5649493574615367),
 ('guadalcanal', 2.5649493574615367),
 ('riget', 2.5649493574615367),
 ('girotti', 2.5649493574615367),
 ('mclaglen', 2.5649493574615367),
 ('unsung', 2.5649493574615367),
 ('sugiyama', 2.5649493574615367),
 ('tissues', 2.5649493574615367),
 ('erendira', 2.5649493574615367),
 ('holloway', 2.5649493574615367),
 ('goring', 2.5649493574615367),
 ('broadbent', 2.5649493574615367),
 ('choi', 2.5649493574615367),
 ('chavo', 2.5649493574615367),
 ('bouvier', 2.5649493574615367),
 ('corbett', 2.5494451709255714),
 ('abu', 2.5389738710582761),
 ('zu', 2.5389738710582761),
 ('warhols', 2.5389738710582761),
 ('gandhi', 2.5389738710582761),
 ('sammi', 2.5389738710582761),
 ('delightfully', 2.5257286443082556),
 ('sirk', 2.5199979695992702),
 ('rosenstrasse', 2.5123056239761148),
 ('creasy', 2.5055259369907361),
 ('braveheart', 2.5014359517392109),
 ('cacoyannis', 2.4849066497880004),
 ('natures', 2.4849066497880004),
 ('hayao', 2.4849066497880004),
 ('vierde', 2.4849066497880004),
 ('poonam', 2.4849066497880004),
 ('barrister', 2.4849066497880004),
 ('lupino', 2.4849066497880004),
 ('perdition', 2.4849066497880004),
 ('attila', 2.4849066497880004),
 ('bressart', 2.4849066497880004),
 ('mcadam', 2.4849066497880004),
 ('euripides', 2.4849066497880004),
 ('holodeck', 2.4849066497880004),
 ('herge', 2.4849066497880004),
 ('anselmo', 2.4849066497880004),
 ('bouzaglo', 2.4849066497880004),
 ('lassalle', 2.4849066497880004),
 ('strindberg', 2.4849066497880004),
 ('yuzna', 2.4849066497880004),
 ('killian', 2.4849066497880004),
 ('hecht', 2.4849066497880004),
 ('kazan', 2.4849066497880004),
 ('binder', 2.4849066497880004),
 ('clutters', 2.4849066497880004),
 ('parminder', 2.4849066497880004),
 ('luger', 2.4849066497880004),
 ('blackadder', 2.4849066497880004),
 ('hanlon', 2.4849066497880004),
 ('rideau', 2.4849066497880004),
 ('trenholm', 2.4849066497880004),
 ('balduin', 2.4849066497880004),
 ('unpretentious', 2.4849066497880004),
 ('talos', 2.4849066497880004),
 ('gallico', 2.4849066497880004),
 ('lafitte', 2.4849066497880004),
 ('presque', 2.4849066497880004),
 ('bischoff', 2.4849066497880004),
 ('santiago', 2.4849066497880004),
 ('mcphillip', 2.4849066497880004),
 ('yeon', 2.4849066497880004),
 ('vonnegut', 2.4638532405901681),
 ('mccoy', 2.456735772821304),
 ('taker', 2.456735772821304),
 ('flawless', 2.451005098112319),
 ('othello', 2.4485390056171252),
 ('abbey', 2.4423470353692043),
 ('mahatma', 2.4423470353692043),
 ('godmother', 2.4423470353692043),
 ('judi', 2.4423470353692043),
 ('mcnally', 2.4423470353692043),
 ('natali', 2.4423470353692043),
 ('jonestown', 2.4423470353692043),
 ('novak', 2.4361164856185682),
 ('durbin', 2.4277482359480516),
 ('christy', 2.4203681286504293),
 ('cheadle', 2.4159137783010487),
 ('arrondissement', 2.3978952727983707),
 ('vadar', 2.3978952727983707),
 ('bolan', 2.3978952727983707),
 ('stockwell', 2.3978952727983707),
 ('soapdish', 2.3978952727983707),
 ('gorris', 2.3978952727983707),
 ('dragoon', 2.3978952727983707),
 ('rf', 2.3978952727983707),
 ('tetsur', 2.3978952727983707),
 ('shep', 2.3978952727983707),
 ('gundams', 2.3978952727983707),
 ('nord', 2.3978952727983707),
 ('pike', 2.3978952727983707),
 ('prologues', 2.3978952727983707),
 ('gracia', 2.3978952727983707),
 ('hallen', 2.3978952727983707),
 ('nyqvist', 2.3978952727983707),
 ('eminent', 2.3978952727983707),
 ('wilhelm', 2.3978952727983707),
 ('dorfman', 2.3978952727983707),
 ('nandini', 2.3978952727983707),
 ('antonietta', 2.3978952727983707),
 ('bartel', 2.3978952727983707),
 ('pei', 2.3978952727983707),
 ('fellowes', 2.3978952727983707),
 ('leaud', 2.3978952727983707),
 ('lok', 2.3978952727983707),
 ('sjoman', 2.3978952727983707),
 ('filone', 2.3978952727983707),
 ('hanka', 2.3978952727983707),
 ('rawhide', 2.3978952727983707),
 ('fanshawe', 2.3978952727983707),
 ('bruhl', 2.3978952727983707),
 ('showings', 2.3978952727983707),
 ('zp', 2.3978952727983707),
 ('thursby', 2.3978952727983707),
 ('faultless', 2.3978952727983707),
 ('hoss', 2.3978952727983707),
 ('seine', 2.3978952727983707),
 ('fuller', 2.3978952727983707),
 ('woronov', 2.3978952727983707),
 ('sweetin', 2.3978952727983707),
 ('cookbook', 2.3978952727983707),
 ('bazza', 2.3978952727983707),
 ('yasmin', 2.3978952727983707),
 ('stitzer', 2.3978952727983707),
 ('radiant', 2.3978952727983707),
 ('spacecamp', 2.3978952727983707),
 ('noriko', 2.3978952727983707),
 ('unsurpassed', 2.3978952727983707),
 ('viennese', 2.3978952727983707),
 ('ramones', 2.3978952727983707),
 ('starewicz', 2.3978952727983707),
 ('eisenhower', 2.3978952727983707),
 ('waterman', 2.3978952727983707),
 ('regent', 2.3978952727983707),
 ('faust', 2.3978952727983707),
 ('huns', 2.3978952727983707),
 ('taoist', 2.3978952727983707),
 ('capano', 2.3978952727983707),
 ('cannavale', 2.3978952727983707),
 ('atul', 2.3978952727983707),
 ('dorsey', 2.3978952727983707),
 ('muska', 2.3978952727983707),
 ('tykwer', 2.3978952727983707),
 ('pita', 2.367123614131617),
 ('cal', 2.3608540011180215),
 ('schmid', 2.3513752571634776),
 ('johnston', 2.3513752571634776),
 ('brisson', 2.3513752571634776),
 ('oberon', 2.3513752571634776),
 ('elsa', 2.3513752571634776),
 ('reservations', 2.3513752571634776),
 ('marylee', 2.3513752571634776),
 ('winchester', 2.3353749158170367),
 ('jabba', 2.3272777055844172),
 ('chamberlain', 2.3191143949452564),
 ('homeward', 2.3025850929940459),
 ('coop', 2.3025850929940459),
 ('rea', 2.3025850929940459),
 ('manny', 2.3025850929940459),
 ('girlfight', 2.3025850929940459),
 ('colman', 2.3025850929940459),
 ('jud', 2.3025850929940459),
 ('tigerland', 2.3025850929940459),
 ('montrose', 2.3025850929940459),
 ('ungar', 2.3025850929940459),
 ('bannister', 2.3025850929940459),
 ('hundstage', 2.3025850929940459),
 ('flamenco', 2.3025850929940459),
 ('haines', 2.3025850929940459),
 ('hanzo', 2.2772672850097559),
 ('fagin', 2.2772672850097559),
 ('carla', 2.2772672850097559),
 ('olympia', 2.2686835413183641),
 ('sullavan', 2.2686835413183641),
 ('aunts', 2.2686835413183641),
 ('sabrina', 2.2643638801738479),
 ('superbly', 2.2600254785752498),
 ('tully', 2.2512917986064953),
 ('beetle', 2.2512917986064953),
 ('linklater', 2.2512917986064953),
 ('aborigines', 2.2512917986064953),
 ('peters', 2.2512917986064953),
 ('hickok', 2.2512917986064953),
 ('mccartney', 2.2512917986064953),
 ('sweetly', 2.2512917986064953),
 ('zentropa', 2.2512917986064953),
 ('elia', 2.2512917986064953),
 ('gigi', 2.2512917986064953),
 ('northam', 2.2407096892759584),
 ('tomlinson', 2.2335922215070942),
 ('tenant', 2.2284771208403238),
 ('kalifornia', 2.224623551524334),
 ('influential', 2.224623551524334),
 ('stardust', 2.2192034840549946),
 ('kinnear', 2.2155737160044158),
 ('benet', 2.1972245773362196),
 ('raines', 2.1972245773362196),
 ('vertigo', 2.1972245773362196),
 ('raoul', 2.1972245773362196),
 ('magnificently', 2.1972245773362196),
 ('hatcher', 2.1972245773362196),
 ('squire', 2.1972245773362196),
 ('quartier', 2.1972245773362196),
 ('complement', 2.1972245773362196),
 ('treasured', 2.1972245773362196),
 ('cheung', 2.1690537003695232),
 ('stevenson', 2.1690537003695232),
 ('finely', 2.1690537003695232),
 ('georges', 2.1649637151179979),
 ('marvelously', 2.1594842493533721),
 ('perfection', 2.1594842493533721),
 ('weir', 2.1594842493533721),
 ('rukh', 2.1594842493533721),
 ('iris', 2.1594842493533721),
 ('enchanting', 2.1517622032594619),
 ('pressburger', 2.1400661634962708),
 ('mahoney', 2.1400661634962708),
 ('brodie', 2.1400661634962708),
 ('astaire', 2.1400661634962708),
 ('speakeasy', 2.1400661634962708),
 ('anand', 2.1400661634962708),
 ('sailing', 2.1400661634962708),
 ('spellbinding', 2.1400661634962708),
 ('cartwright', 2.1400661634962708),
 ('kennel', 2.1400661634962708),
 ('leung', 2.1400661634962708),
 ('celine', 2.1400661634962708),
 ('curr', 2.1400661634962708),
 ('dixon', 2.1400661634962708),
 ('province', 2.1400661634962708),
 ('trier', 2.1316272948504063),
 ('pecker', 2.1282317058492679),
 ('wodehouse', 2.120263536200091),
 ('miyazaki', 2.120263536200091),
 ('darius', 2.1102132003465894),
 ('marjorie', 2.1102132003465894),
 ('hark', 2.1102132003465894),
 ('vulnerability', 2.1102132003465894),
 ('devotion', 2.1041341542702074),
 ('tackled', 2.0794415416798357),
 ('footlight', 2.0794415416798357),
 ('lupin', 2.0794415416798357),
 ('malone', 2.0794415416798357),
 ('janeway', 2.0794415416798357),
 ('genesis', 2.0794415416798357),
 ('duryea', 2.0794415416798357),
 ('abbot', 2.0794415416798357),
 ('fez', 2.0794415416798357),
 ('iago', 2.0794415416798357),
 ('mores', 2.0794415416798357),
 ('benoit', 2.0794415416798357),
 ('braun', 2.0794415416798357),
 ('loomis', 2.0794415416798357),
 ('yang', 2.0794415416798357),
 ('devos', 2.0794415416798357),
 ('romy', 2.0794415416798357),
 ('boothe', 2.0794415416798357),
 ('cheech', 2.0541237336955462),
 ('fairytale', 2.0476928433652555),
 ('askey', 2.0476928433652555),
 ('tel', 2.0476928433652555),
 ('mol', 2.0476928433652555),
 ('ella', 2.0476928433652555),
 ('captures', 2.0386195471595809),
 ('edith', 2.0368819272610401),
 ('duchess', 2.0368819272610401),
 ('tintin', 2.0368819272610401),
 ('curtiz', 2.0368819272610401),
 ('quotable', 2.0368819272610401),
 ('scoop', 2.0314323224934752),
 ('pickford', 2.0314323224934752),
 ('voight', 2.0301704926730531),
 ('wonderfully', 2.0218960560332353),
 ('stalkers', 2.0149030205422647),
 ('saffron', 2.0149030205422647),
 ('sasha', 2.0149030205422647),
 ('accomplishes', 2.0149030205422647),
 ('tetsuo', 2.0149030205422647),
 ('archibald', 2.0149030205422647),
 ('richness', 2.0149030205422647),
 ('broomsticks', 2.0149030205422647),
 ('blaine', 2.0149030205422647),
 ('kessler', 2.0149030205422647),
 ('dearly', 2.0149030205422647),
 ('stubby', 2.0149030205422647),
 ('ephemeral', 2.0149030205422647),
 ('patekar', 2.0149030205422647),
 ('donnell', 2.0149030205422647),
 ('silvio', 2.0149030205422647),
 ('laird', 2.0149030205422647),
 ('goa', 2.0149030205422647),
 ('milton', 2.0149030205422647),
 ('brokedown', 2.0149030205422647),
 ('gilley', 2.0149030205422647),
 ('zorro', 2.0053335695261141),
 ('clarence', 2.0014800002101243),
 ('dandy', 1.9980959022258835),
 ('pawn', 1.9924301646902061),
 ('frailty', 1.9924301646902061),
 ('egan', 1.9924301646902061),
 ('bozz', 1.9924301646902061),
 ('pickpocket', 1.9924301646902061),
 ('heartbreaking', 1.9924301646902061),
 ('venezuela', 1.9810014688665833),
 ('powell', 1.9783454248084671),
 ('wang', 1.9740810260220096),
 ('brosnan', 1.9547990964725592),
 ('cratchit', 1.9459101490553132),
 ('strathairn', 1.9459101490553132),
 ('argentine', 1.9459101490553132),
 ('bafta', 1.9459101490553132),
 ('mala', 1.9459101490553132),
 ('aames', 1.9459101490553132),
 ('stairway', 1.9459101490553132),
 ('gingold', 1.9459101490553132),
 ('singin', 1.9459101490553132),
 ('meena', 1.9459101490553132),
 ('francois', 1.9459101490553132),
 ('refreshingly', 1.9459101490553132),
 ('mostel', 1.9459101490553132),
 ('collinwood', 1.9459101490553132),
 ('truman', 1.9459101490553132),
 ('ida', 1.9459101490553132),
 ('carre', 1.9459101490553132),
 ('trebor', 1.9459101490553132),
 ('transcends', 1.9459101490553132),
 ('preity', 1.9459101490553132),
 ('slipper', 1.9459101490553132),
 ('enthralling', 1.9459101490553132),
 ('henderson', 1.9459101490553132),
 ('masterful', 1.9459101490553132),
 ('rathbone', 1.9459101490553132),
 ('wegener', 1.9459101490553132),
 ('hawke', 1.9459101490553132),
 ('oshii', 1.9459101490553132),
 ('wtc', 1.9459101490553132),
 ('noll', 1.9459101490553132),
 ('sg', 1.927891643552635),
 ('masterson', 1.927891643552635),
 ('sunrise', 1.9252908618525775),
 ('lily', 1.9203768470501485),
 ('lila', 1.9169226121820611),
 ('corbin', 1.9169226121820611),
 ('lighten', 1.9095425048844386),
 ('adelaide', 1.9095425048844386),
 ('expertly', 1.9095425048844386),
 ('turturro', 1.9095425048844386),
 ('bakshi', 1.9029851043382795),
 ('lincoln', 1.9014583864844796),
 ('sumptuous', 1.8971199848858813),
 ('exquisitely', 1.8971199848858813),
 ('firefighters', 1.8971199848858813),
 ('bhandarkar', 1.8971199848858813),
 ('pabst', 1.8971199848858813),
 ('finlay', 1.8971199848858813),
 ('skagway', 1.8971199848858813),
 ('europa', 1.8971199848858813),
 ('darren', 1.8925641683500207),
 ('booker', 1.8870696490323797),
 ('chang', 1.8870696490323797),
 ('tomei', 1.8827312474337816),
 ('kumari', 1.8718021769015913),
 ('spellbound', 1.8718021769015913),
 ('holt', 1.8718021769015913),
 ('cassavettes', 1.8718021769015913),
 ('butterflies', 1.8718021769015913),
 ('lucienne', 1.8718021769015913),
 ('labyrinth', 1.8718021769015913),
 ('maslin', 1.8718021769015913),
 ('coccio', 1.8718021769015913),
 ('iberia', 1.8718021769015913),
 ('impressionist', 1.8718021769015913),
 ('flik', 1.8718021769015913),
 ('schygulla', 1.8718021769015913),
 ('stealer', 1.8718021769015913),
 ('ronda', 1.8718021769015913),
 ('busby', 1.8718021769015913),
 ('bulimia', 1.8718021769015913),
 ('superlative', 1.8718021769015913),
 ('bettany', 1.8718021769015913),
 ('paget', 1.8718021769015913),
 ('ozzie', 1.8718021769015913),
 ('aborigine', 1.8718021769015913),
 ('kher', 1.8718021769015913),
 ('observant', 1.8718021769015913),
 ('cypher', 1.8718021769015913),
 ('collaborators', 1.8718021769015913),
 ('lyman', 1.8718021769015913),
 ('rolle', 1.8718021769015913),
 ('blindness', 1.8718021769015913),
 ('ellie', 1.8718021769015913),
 ('lucile', 1.8718021769015913),
 ('borowczyk', 1.8718021769015913),
 ('informer', 1.8718021769015913),
 ('solicitor', 1.8718021769015913),
 ('greene', 1.8607523407150064),
 ('carell', 1.8588987720656835),
 ('sematary', 1.8562979903656263),
 ('refreshing', 1.8551812956655511),
 ('montana', 1.8538912503350613),
 ('pegg', 1.8523840910444898),
 ('breathtaking', 1.8481124057791867),
 ('bourne', 1.8478489358790986),
 ('lemmon', 1.8458266904983307),
 ('hardwicke', 1.8458266904983307),
 ('teri', 1.8458266904983307),
 ('splendidly', 1.8458266904983307),
 ('electrifying', 1.8458266904983307),
 ('siu', 1.8458266904983307),
 ('twisty', 1.8458266904983307),
 ('uncompromising', 1.8458266904983307),
 ('prix', 1.8458266904983307),
 ('walsh', 1.8325814637483102),
 ('zelda', 1.8325814637483102),
 ('morbius', 1.8325814637483102),
 ('guiness', 1.8325814637483102),
 ('abby', 1.8325814637483102),
 ('brock', 1.8325814637483102),
 ('mendes', 1.8325814637483102),
 ('batwoman', 1.824549292051046),
 ('carface', 1.824549292051046),
 ('keeler', 1.824549292051046),
 ('zabriskie', 1.824549292051046),
 ('connolly', 1.824549292051046),
 ('vincenzo', 1.8191584434161694),
 ('precise', 1.8152899666382492),
 ('parrot', 1.8152899666382492),
 ('steele', 1.8082887711792655),
 ('explores', 1.8082887711792655),
 ('delightful', 1.8002701588959635),
 ('flynn', 1.7996646487351682),
 ('evans', 1.791759469228055),
 ('talespin', 1.791759469228055),
 ('runyon', 1.791759469228055),
 ('travers', 1.791759469228055),
 ('breathes', 1.791759469228055),
 ('perseverance', 1.791759469228055),
 ('enforced', 1.791759469228055),
 ('lumire', 1.791759469228055),
 ('corsaut', 1.791759469228055),
 ('leia', 1.791759469228055),
 ('nicolai', 1.791759469228055),
 ('robust', 1.791759469228055),
 ('demunn', 1.791759469228055),
 ('rory', 1.791759469228055),
 ('trotta', 1.791759469228055),
 ('patric', 1.791759469228055),
 ('massey', 1.791759469228055),
 ('leisen', 1.791759469228055),
 ('nath', 1.791759469228055),
 ('rogen', 1.791759469228055),
 ('weismuller', 1.791759469228055),
 ('shemp', 1.791759469228055),
 ('britton', 1.791759469228055),
 ('tadashi', 1.791759469228055),
 ('culp', 1.791759469228055),
 ('celebrates', 1.791759469228055),
 ('champions', 1.791759469228055),
 ('nan', 1.791759469228055),
 ('geddes', 1.791759469228055),
 ('examines', 1.791759469228055),
 ('heightens', 1.791759469228055),
 ('dedlock', 1.791759469228055),
 ('raja', 1.791759469228055),
 ('prem', 1.791759469228055),
 ('zandalee', 1.791759469228055),
 ('jong', 1.791759469228055),
 ('conor', 1.791759469228055),
 ('linden', 1.791759469228055),
 ('franks', 1.791759469228055),
 ('crouse', 1.791759469228055),
 ('auer', 1.791759469228055),
 ('witherspoon', 1.791759469228055),
 ('uproarious', 1.791759469228055),
 ('rafael', 1.791759469228055),
 ('strangler', 1.791759469228055),
 ('strides', 1.791759469228055),
 ('tumultuous', 1.791759469228055),
 ('advent', 1.791759469228055),
 ('colonialism', 1.791759469228055),
 ('parisian', 1.791759469228055),
 ('mischa', 1.791759469228055),
 ('mower', 1.791759469228055),
 ('bearer', 1.791759469228055),
 ('undying', 1.791759469228055),
 ('trejo', 1.791759469228055),
 ('marcus', 1.791759469228055),
 ('chess', 1.7797832781813394),
 ('andrews', 1.7764919970972666),
 ('homer', 1.7692866133759964),
 ('apartheid', 1.7635885922613586),
 ('beautifully', 1.7626953362841438),
 ('soccer', 1.7578579175523736),
 ('foch', 1.7578579175523736),
 ('maclean', 1.7578579175523736),
 ('friendships', 1.7578579175523736),
 ('deliciously', 1.7491998548092591),
 ('reginald', 1.7491998548092591),
 ('todesking', 1.7491998548092591),
 ('ira', 1.7491998548092591),
 ('miners', 1.7491998548092591),
 ('lumet', 1.7462970951512977),
 ('affection', 1.7452394535931621),
 ('bittersweet', 1.742969305058623),
 ('cedric', 1.742969305058623),
 ('elvira', 1.7397031072720019),
 ('provo', 1.7346010553881064),
 ('hoon', 1.7346010553881064),
 ('carrell', 1.7346010553881064),
 ('ilona', 1.7346010553881064),
 ('caprice', 1.7346010553881064),
 ('scorpion', 1.7346010553881064),
 ('entranced', 1.7346010553881064),
 ('vulcan', 1.7346010553881064),
 ('kovacs', 1.7346010553881064),
 ('custer', 1.7346010553881064),
 ('shefali', 1.7346010553881064),
 ('axel', 1.7346010553881064),
 ('ullman', 1.7346010553881064),
 ('deft', 1.7346010553881064),
 ('dell', 1.7346010553881064),
 ('bureaucracy', 1.7346010553881064),
 ('radium', 1.7346010553881064),
 ('stepsisters', 1.7346010553881064),
 ('silhouette', 1.7346010553881064),
 ('kidman', 1.729239112246721),
 ('paperhouse', 1.7227665977411035),
 ('underrated', 1.7197859696029656),
 ('sopranos', 1.7197859696029656),
 ('quintessential', 1.7176514970743331),
 ('myrna', 1.7176514970743331),
 ('gripping', 1.7165360479904674),
 ('superb', 1.7091514458966952),
 ('celeste', 1.7047480922384253),
 ('extravagant', 1.7047480922384253),
 ('borden', 1.7047480922384253),
 ('partnership', 1.7047480922384253),
 ('eduardo', 1.7047480922384253),
 ('rediscovered', 1.7047480922384253),
 ('delon', 1.7047480922384253),
 ('lassick', 1.7047480922384253),
 ('kibbee', 1.7047480922384253),
 ('buttgereit', 1.7047480922384253),
 ('cameroon', 1.7047480922384253),
 ('rippner', 1.7047480922384253),
 ('doolittle', 1.7047480922384253),
 ('perceptions', 1.7047480922384253),
 ('albuquerque', 1.7047480922384253),
 ('friel', 1.7047480922384253),
 ('birdie', 1.7047480922384253),
 ('nunsploitation', 1.7047480922384253),
 ('mavens', 1.7047480922384253),
 ('gallows', 1.7047480922384253),
 ('rail', 1.7047480922384253),
 ('dukakis', 1.7047480922384253),
 ('coveted', 1.7047480922384253),
 ('mastery', 1.7047480922384253),
 ('connecticut', 1.7047480922384253),
 ('gorshin', 1.7047480922384253),
 ('expansion', 1.7047480922384253),
 ('poirot', 1.7047480922384253),
 ('expressionistic', 1.7047480922384253),
 ('snare', 1.7047480922384253),
 ('pension', 1.7047480922384253),
 ('warms', 1.7047480922384253),
 ('montand', 1.7047480922384253),
 ('dickinson', 1.7047480922384253),
 ('sternberg', 1.7047480922384253),
 ('moonstruck', 1.7047480922384253),
 ('nina', 1.7047480922384253),
 ('minton', 1.7047480922384253),
 ('civilized', 1.7047480922384253),
 ('criterion', 1.7047480922384253),
 ('apollonia', 1.7047480922384253),
 ('ealing', 1.6916760106710724),
 ('han', 1.6916760106710724),
 ('weaves', 1.6863989535702288),
 ('yoda', 1.6863989535702288),
 ('bagdad', 1.6863989535702288),
 ('deliverance', 1.6863989535702288),
 ('paula', 1.6863989535702288),
 ('holm', 1.6863989535702288),
 ('determination', 1.6817585740137264),
 ('mvp', 1.6739764335716716),
 ('janice', 1.6739764335716716),
 ('romanticized', 1.6739764335716716),
 ('doodlebops', 1.6739764335716716),
 ('textile', 1.6739764335716716),
 ('scola', 1.6739764335716716),
 ('sceptical', 1.6739764335716716),
 ('krabbe', 1.6739764335716716),
 ('caleb', 1.6739764335716716),
 ('schmidt', 1.6739764335716716),
 ('bulldog', 1.6739764335716716),
 ('petition', 1.6739764335716716),
 ('tierney', 1.6739764335716716),
 ('muller', 1.6739764335716716),
 ('crashers', 1.6739764335716716),
 ('jerome', 1.6739764335716716),
 ('delight', 1.6714733033535532),
 ('reeve', 1.6677068205580761),
 ('welles', 1.6677068205580761),
 ('zelah', 1.6650077635889111),
 ('sadness', 1.663505133704376),
 ('meatball', 1.6582280766035324),
 ('proposes', 1.6582280766035324),
 ('accustomed', 1.6582280766035324),
 ('palsy', 1.6582280766035324),
 ('hermann', 1.6582280766035324),
 ('shia', 1.6582280766035324),
 ('technicolor', 1.65455834771457),
 ('ae', 1.6529230243738393),
 ('joyous', 1.6486586255873816),
 ('maintained', 1.6486586255873816),
 ('tenderness', 1.6486586255873816),
 ('restoration', 1.6486586255873816),
 ('soylent', 1.6486586255873816),
 ('nicky', 1.6486586255873816),
 ('kline', 1.6422277352570913),
 ('sinatra', 1.6389967146756448),
 ('touching', 1.637217476541176),
 ('stadium', 1.634130525024472),
 ('marisa', 1.634130525024472),
 ('gershwin', 1.6314168191528755),
 ('timeless', 1.62924053973028),
 ('macy', 1.6211339521972916),
 ('unforgettable', 1.6177367152487956),
 ('favorites', 1.6158688027643908),
 ('stewart', 1.6119987332957739),
 ('competitor', 1.6094379124341003),
 ('jonny', 1.6094379124341003),
 ('mammy', 1.6094379124341003),
 ('compliments', 1.6094379124341003),
 ('nunez', 1.6094379124341003),
 ('advancing', 1.6094379124341003),
 ('regency', 1.6094379124341003),
 ('roberta', 1.6094379124341003),
 ('ponderosa', 1.6094379124341003),
 ('priorities', 1.6094379124341003),
 ('synthesis', 1.6094379124341003),
 ('internationally', 1.6094379124341003),
 ('considerations', 1.6094379124341003),
 ('hoodlums', 1.6094379124341003),
 ('florinda', 1.6094379124341003),
 ('eytan', 1.6094379124341003),
 ('grasshopper', 1.6094379124341003),
 ('hartley', 1.6094379124341003),
 ('taka', 1.6094379124341003),
 ('retriever', 1.6094379124341003),
 ('shanks', 1.6094379124341003),
 ('paxinou', 1.6094379124341003),
 ('tsing', 1.6094379124341003),
 ('panda', 1.6094379124341003),
 ('kurosawa', 1.6094379124341003),
 ('pendleton', 1.6094379124341003),
 ('grayson', 1.6094379124341003),
 ('ringo', 1.6094379124341003),
 ('mammoth', 1.6094379124341003),
 ('everytown', 1.6094379124341003),
 ('moulin', 1.6094379124341003),
 ('zenith', 1.6094379124341003),
 ('perceptive', 1.6094379124341003),
 ('franchot', 1.6094379124341003),
 ('lanchester', 1.6094379124341003),
 ('prelude', 1.6094379124341003),
 ('funhouse', 1.6094379124341003),
 ('humanism', 1.6094379124341003),
 ('glacier', 1.6094379124341003),
 ('weber', 1.6094379124341003),
 ('patten', 1.6094379124341003),
 ('cocktails', 1.6094379124341003),
 ('antidote', 1.6094379124341003),
 ('repulsion', 1.6094379124341003),
 ('serrault', 1.6094379124341003),
 ('outstandingly', 1.6094379124341003),
 ('breakdancing', 1.6094379124341003),
 ('noire', 1.6094379124341003),
 ('monarchy', 1.6094379124341003),
 ('sullivan', 1.6094379124341003),
 ('blier', 1.6094379124341003),
 ('wai', 1.6094379124341003),
 ('duets', 1.6094379124341003),
 ('taft', 1.6094379124341003),
 ('mcgrath', 1.6094379124341003),
 ('duc', 1.6094379124341003),
 ('airwolf', 1.6094379124341003),
 ('rugged', 1.6094379124341003),
 ('bloch', 1.6094379124341003),
 ('judson', 1.6094379124341003),
 ('henri', 1.6094379124341003),
 ('candid', 1.6094379124341003),
 ('meloni', 1.6094379124341003),
 ('chico', 1.6094379124341003),
 ('anansa', 1.6094379124341003),
 ('hahk', 1.6094379124341003),
 ('complexities', 1.6094379124341003),
 ('kabal', 1.6094379124341003),
 ('roshan', 1.6094379124341003),
 ('orphaned', 1.6094379124341003),
 ('sorbonne', 1.6094379124341003),
 ('summertime', 1.6094379124341003),
 ('restrictive', 1.6094379124341003),
 ('dahlia', 1.6094379124341003),
 ('cruz', 1.6094379124341003),
 ('enforcer', 1.6094379124341003),
 ('extraordinary', 1.6094379124341003),
 ('unavailable', 1.6094379124341003),
 ('hedy', 1.6094379124341003),
 ('congrats', 1.6094379124341003),
 ('brilliantly', 1.5950491749820008),
 ('einstein', 1.5910887737659039),
 ('liu', 1.5910887737659039),
 ('clara', 1.5910887737659039),
 ('dustin', 1.589235205116581),
 ('iran', 1.5841201044498106),
 ('conductor', 1.5841201044498106),
 ('shanghai', 1.5804503755608481),
 ('rainer', 1.575536360758419),
 ('alienate', 1.575536360758419),
 ('mesmerizing', 1.5723966407537513),
 ('raul', 1.5686159179138452),
 ('friendship', 1.5677652160335325),
 ('wonderful', 1.5645425925262093),
 ('moriarty', 1.5581446180465499),
 ('corinne', 1.5581446180465499),
 ('heartwarming', 1.5581446180465499),
 ('scarlett', 1.5581446180465499),
 ('sergeants', 1.5581446180465499),
 ('swordplay', 1.5581446180465499),
 ('layered', 1.5581446180465499),
 ...]

In [157]:
# words most frequently seen in a review with a "NEGATIVE" label
list(reversed(pos_neg_ratios.most_common()))[0:30]


Out[157]:
[('boll', -4.9698132995760007),
 ('uwe', -4.6249728132842707),
 ('thunderbirds', -4.1271343850450917),
 ('beowulf', -4.1108738641733114),
 ('dahmer', -3.9889840465642745),
 ('wayans', -3.9318256327243257),
 ('seagal', -3.6441435602725449),
 ('gamera', -3.3322045101752038),
 ('dreck', -3.2708355637989119),
 ('unwatchable', -3.2580965380214821),
 ('stinker', -3.208825489014699),
 ('mst', -2.9502698994772336),
 ('incoherent', -2.9368917735310576),
 ('flimsy', -2.9267394020670396),
 ('dillinger', -2.8332133440562162),
 ('yawn', -2.8183982582710754),
 ('unfunny', -2.6922395950755678),
 ('ugh', -2.6210388241125804),
 ('turd', -2.6210388241125804),
 ('waste', -2.6193845640165541),
 ('blah', -2.5704288232261625),
 ('slugs', -2.5649493574615367),
 ('tripe', -2.4986999719203364),
 ('wtf', -2.4849066497880004),
 ('horrid', -2.4849066497880004),
 ('pointless', -2.4553061800117097),
 ('atrocious', -2.4259083090260445),
 ('damme', -2.4107986776342782),
 ('redeeming', -2.3682390632154826),
 ('prom', -2.3608540011180215)]

Wow, there’s really something to this theory! As we can see, there are clearly terms in movie reviews that have correlation with our output labels. So, if we think there might be strong correlation between the words present in a particular review and the sentiment of that review, what should our network take as input and then predict? Let me put it a different way: If we think that there is correlation between the “vocabulary” of a particular review and the sentiment of that review, what should be the input and output to our neural network? The input should be the “vocabulary of the review” and the output should be whether or not the review is positive or negative!

Now that we have some idea that this task is possible (and where we want the network to find correlation), let’s try to train a neural network to predict sentiment based on the vocabulary of a movie review.

Transforming Text to Numbers

The next challenge is to transform our datasets into something that the neural network can read.

As I’m sure you’ve learned, neural networks are made up of layers of interconnected “neurons”. The first layer is where our input data “goes in” to the network. Any particular “input neuron” can take exactly two kinds of inputs, binary inputs and “real valued” inputs. Previously, you’ve been training networks on raw, continuous data, real valued inputs. However, now we’re modeling whether different input terms “exist” or “do not exist” in a movie review. When we model something that either “exists” or “does not exiest” or when something is either “true” or “false”, we want to use “binary” inputs to our neural network. This use of binary values is called "one-hot encoding". Let me show you what I mean.

Example Predictions


In [85]:
from IPython.display import Image

review = "This was a horrible, terrible movie."

Image(filename='sentiment_network.png')


Out[85]:

In [86]:
review = "The movie was excellent"

Image(filename='sentiment_network_pos.png')


Out[86]:

The Input

Let’s say our entire movie review corpus has 10,000 words. Given a single movie review ("This was a horrible, terrible movie"), we’re going to put a “1” in the input of our neural network for every word that exists in the review, and a 0 everywhere else. So, given our 10,000 words, a movie review with 6 words would have 6 neurons with a “1” and 9,994 neurons with a “0”. The picture above is a miniturized version of this, displaying how we input a "1" for the words "horrible" and "terrible" while inputting a "0" for the word "excellent" because it was not present in the review.

The Output

In the same way, we want our network to either predict that the input is “positive” or “negative”. Now, our networks can’t write “positive” or “negative”, so we’re going to instead have another single neuron that represents “positive” when it is a “1” and “negative” when it is a “0”. In this way, our network can give us a number that we will interpret as “positive” or “negative”.

Big Picture

What we’re actually doing here is creating a “derivative dataset” from our movie reviews. Neural networks, after all, can’t read text. So, what we’re doing is identifying the “source of correlation” in our two datasets and creating a derivative dataset made up of numbers that preserve the patterns that we care about. In our input dataset, that pattern is the existence or non-existence of a particular word. In our output dataset, that pattern is whether a statement is positive or negative. Now we’ve converted our patterns into something our network can understand! Our network is going to look for correlation between the 1s and 0s in our input and the 1s and 0s in our output, and if it can do so it has learned to predict the sentiment of movie reviews. Now that our data is ready for the network, let’s start building the network.

Creating the Input Data

As we just learned above, in order for our neural network to predict on a movie review, we have to be able to create an input layer of 1s and 0s that correlates with the words present in a review. Let's start by creating a function that can take a review and generate this layer of 1s and 0s.

In order to create this function, we first must decide how many input neurons we need. The answer is quite simple. Since we want our network's input to be able to represent the presence or absence of any word in the vocabulary, we need one node per vocabulary term. So, our input layer size is the size of our vocabulary. Let's calculate that.


In [87]:
vocab = set(total_counts.keys())
vocab_size = len(vocab)
print(vocab_size)


74074

And now we can initialize our (empty) input layer as vector of 0s. We'll modify it later by putting "1"s in various positions.


In [88]:
import numpy as np

layer_0 = np.zeros((1,vocab_size))
layer_0


Out[88]:
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.]])

And now we want to create a function that will set our layer_0 list to the correct sequence of 1s and 0s based on a single review. Now if you remember our picture before, you might have noticed something. Each word had a specific place in the input of our network.


In [89]:
from IPython.display import Image
Image(filename='sentiment_network.png')


Out[89]:

In order to create a function that can update our layer_0 variable based on a review, we have to decide which spots in our layer_0 vector (list of numbers) correlate with each word. Truth be told, it doesn't matter which ones we choose, only that we pick spots for each word and stick with them. Let's decide those positions now and store them in a python dictionary called "word2index".


In [90]:
word2index = {}

for i,word in enumerate(vocab):
    word2index[word] = i
word2index


Out[90]:
{'': 0,
 'arlana': 1,
 'baphomets': 4,
 'shibasaki': 3,
 'disarming': 57944,
 'emptiness': 12444,
 'prozess': 5,
 'ladislav': 8,
 'lahm': 7,
 'carthage': 49481,
 'campiest': 9,
 'ally': 10,
 'rakastin': 67316,
 'generated': 11,
 'bumblers': 12,
 'maximizes': 18210,
 'vaterland': 14,
 'lasciviously': 25134,
 'unprepared': 15,
 'signification': 16,
 'canceled': 12448,
 'classy': 50510,
 'atavistic': 17,
 'buza': 18,
 'rda': 19,
 'underdogs': 20,
 'fakk': 21,
 'capper': 61784,
 'magnificently': 22,
 'underwritten': 49485,
 'pak': 23,
 'smg': 26,
 'creation': 27,
 'peevishness': 29,
 'giddiness': 18623,
 'cot': 30,
 'apossibly': 34,
 'preordered': 32,
 'sylvio': 33,
 'singelton': 35,
 'underpinning': 36,
 'moaning': 37,
 'dau': 38,
 'westerns': 30331,
 'pinning': 40,
 'replenish': 42,
 'emancipated': 43,
 'wolfstein': 44,
 'salvific': 71151,
 'insisted': 45,
 'playoffs': 46,
 'zabalza': 49,
 'battre': 50,
 'nahhh': 6,
 'santacruz': 45075,
 'fargan': 51,
 'weberian': 52,
 'benoit': 54,
 'straighter': 56,
 'phoenician': 61793,
 'competently': 49494,
 'clatter': 58,
 'notch': 37126,
 'potholes': 59,
 'responsibilty': 60,
 'financing': 49495,
 'splices': 61,
 'atmospheric': 62,
 'sounding': 63,
 'gwoemul': 67,
 'mulls': 68,
 'elephant': 66,
 'margot': 66134,
 'thenardier': 19210,
 'intentions': 70,
 'sentimentalising': 76,
 'cornea': 75,
 'chainsaws': 73,
 'macgruder': 74,
 'verse': 63869,
 'crouse': 77,
 'tyros': 78,
 'knowledges': 13,
 'emmy': 57060,
 'lupe': 80,
 'sundown': 81,
 'pirates': 82,
 'sidewalks': 62419,
 'mandible': 85,
 'oks': 86,
 'crusierweight': 49506,
 'maims': 87,
 'bwana': 64644,
 'remove': 88,
 'devastation': 89,
 'nasally': 90,
 'sirens': 91,
 'nadanova': 94,
 'dreyfuss': 93,
 'firefight': 95,
 'kascier': 98,
 'devin': 100,
 'ferrigno': 69600,
 'gratingly': 102,
 'blustery': 103,
 'imported': 72680,
 'provo': 104,
 'glares': 106,
 'noriyuki': 108,
 'unspecific': 109,
 'revives': 67334,
 'os': 110,
 'scowls': 69442,
 'ambassador': 111,
 'svengoolie': 113,
 'prosecution': 52897,
 'preferentiate': 114,
 'openminded': 115,
 'chore': 53141,
 'winnings': 116,
 'shintaro': 117,
 'fanbases': 118,
 'unforgetable': 119,
 'ashes': 29486,
 'gucht': 120,
 'straggle': 125,
 'delegation': 122,
 'boetticher': 123,
 'oughts': 124,
 'reactor': 65420,
 'fulcis': 126,
 'vacationers': 127,
 'detained': 12464,
 'passing': 21209,
 'inhospitable': 128,
 'drainboard': 131,
 'weekdays': 130,
 'despicableness': 132,
 'caravaggio': 55844,
 'bedingfield': 134,
 'msmyth': 135,
 'legislature': 136,
 'sanctimoniously': 137,
 'haff': 138,
 'psych': 139,
 'interwhined': 143,
 'boyce': 142,
 'swashbucklers': 144,
 'milne': 146,
 'piquor': 147,
 'potente': 148,
 'blackblood': 149,
 'persuing': 152,
 'goodloe': 154,
 'creepshow': 153,
 'sensibly': 155,
 'scout': 156,
 'afrika': 158,
 'kwan': 37141,
 'prepubescent': 61810,
 'compromising': 159,
 'publically': 160,
 'vdb': 161,
 'julissa': 162,
 'lulls': 49517,
 'lockett': 163,
 'mousse': 164,
 'dipper': 165,
 'cihangir': 166,
 'erfoud': 167,
 'unenviable': 168,
 'christianty': 24,
 'bea': 170,
 'novarro': 12471,
 'culloden': 171,
 'anxiety': 173,
 'schaech': 18022,
 'comportaments': 12472,
 'upholding': 175,
 'regeneration': 25,
 'onside': 53893,
 'cockiness': 61813,
 'klebb': 176,
 'reclaims': 177,
 'synthesizes': 178,
 'vincente': 179,
 'periodic': 180,
 'criminey': 181,
 'exceptional': 182,
 'emergance': 185,
 'steakley': 187,
 'lohman': 188,
 'heartbreaker': 189,
 'treviranus': 190,
 'context': 191,
 'rapyuta': 192,
 'tout': 193,
 'vahtang': 28,
 'naam': 196,
 'spare': 197,
 'vaseline': 17132,
 'triskelion': 198,
 'dimensions': 199,
 'stingy': 200,
 'bayliss': 201,
 'squirmed': 203,
 'unusually': 204,
 'narcissus': 12477,
 'mondi': 44151,
 'dole': 206,
 'sellam': 207,
 'otoko': 212,
 'uns': 210,
 'inevitable': 211,
 'impacted': 5889,
 'libidinal': 213,
 'dt': 214,
 'rugrats': 31,
 'wsj': 215,
 'jove': 216,
 'portabellow': 218,
 'anchorwoman': 220,
 'coer': 221,
 'sinny': 222,
 'punctuality': 224,
 'celebrate': 49527,
 'lettuce': 225,
 'kickoff': 24694,
 'jianjun': 228,
 'democrat': 227,
 'codenamealexa': 229,
 'fades': 230,
 'cynthia': 54638,
 'trotti': 234,
 'khrystyne': 233,
 'branding': 72976,
 'kumari': 235,
 'stunners': 236,
 'explicit': 237,
 'rosenmller': 241,
 'potatoes': 39355,
 'redack': 242,
 'absentee': 70414,
 'gustafson': 41,
 'bummed': 244,
 'ethnocentric': 245,
 'westing': 48264,
 'gluttonous': 54096,
 'baitz': 246,
 'prodigal': 250,
 'modulation': 249,
 'restricting': 61823,
 'baba': 251,
 'jays': 49536,
 'macbook': 37148,
 'considerable': 252,
 'arouses': 49537,
 'bover': 60519,
 'sandwiched': 256,
 'albania': 255,
 'ao': 257,
 'windstorm': 258,
 'didgeridoo': 262,
 'trueba': 260,
 'oozed': 261,
 'realisations': 266,
 'taandav': 264,
 'stalled': 265,
 'chal': 37155,
 'excution': 267,
 'maverick': 268,
 'qing': 269,
 'mode': 54641,
 'av': 271,
 'kraggartians': 272,
 'baer': 12488,
 'honorary': 24700,
 'nubes': 273,
 'encircled': 65574,
 'murray': 24704,
 'bandwidth': 48,
 'patent': 274,
 'eschewing': 276,
 'furballs': 277,
 'gunilla': 278,
 'vaut': 279,
 'nan': 280,
 'lymon': 281,
 'nightmaressuch': 53214,
 'deteriorates': 282,
 'mental': 25537,
 'riffraff': 283,
 'laxitive': 284,
 'incas': 285,
 'niall': 286,
 'thankfuly': 290,
 'dictatorial': 288,
 'sisk': 289,
 'cinequest': 293,
 'dixit': 292,
 'dudikoff': 295,
 'robinson': 296,
 'teeter': 297,
 'torchon': 298,
 'sullenly': 12491,
 'praised': 299,
 'amurrika': 34339,
 'reifenstal': 301,
 'superfical': 302,
 'dfroqu': 69531,
 'amusements': 303,
 'anthropomorphising': 304,
 'cashing': 307,
 'dysfuntional': 306,
 'performace': 309,
 'defrost': 310,
 'grauman': 312,
 'jami': 313,
 'rasta': 315,
 'thunderbirds': 316,
 'innocently': 317,
 'forsythe': 53,
 'uglier': 321,
 'psychoanalyze': 325,
 'saluting': 322,
 'neve': 324,
 'slaps': 327,
 'ery': 328,
 'herzegovina': 55,
 'panico': 332,
 'parishioners': 333,
 'criminality': 331,
 'vicey': 59100,
 'relieving': 335,
 'riffen': 336,
 'respectfully': 337,
 'landons': 338,
 'pendragon': 61830,
 'superbly': 339,
 'farmzoid': 340,
 'indianapolis': 341,
 'haughty': 345,
 'fortuitous': 7100,
 'mistrust': 72825,
 'forefathers': 346,
 'grimm': 52975,
 'dedication': 57,
 'applegate': 64775,
 'restarts': 347,
 'betters': 12496,
 'small': 351,
 'lillian': 349,
 'pearce': 350,
 'feathered': 353,
 'trouper': 48180,
 'tarintino': 354,
 'winks': 355,
 'countermeasures': 356,
 'mcdonell': 357,
 'projecting': 358,
 'rounders': 361,
 'kickass': 362,
 'nella': 363,
 'thier': 364,
 'cancels': 365,
 'imparted': 366,
 'twitching': 368,
 'probably': 37173,
 'stripping': 369,
 'maitresse': 370,
 'alum': 55627,
 'taxfree': 371,
 'saga': 37175,
 'simonsons': 372,
 'bullet': 373,
 'seminal': 374,
 'dateing': 377,
 'sharron': 64,
 'hitchcockometer': 378,
 'element': 379,
 'acorn': 380,
 'hemo': 381,
 'restraints': 382,
 'anticipated': 383,
 'overstating': 386,
 'muscleheads': 391,
 'difference': 389,
 'helmsman': 390,
 'froze': 392,
 'sesilia': 37177,
 'seinfield': 393,
 'unconfident': 394,
 'torpedoes': 41817,
 'crains': 395,
 'trends': 397,
 'fagan': 398,
 'payne': 399,
 'personation': 404,
 'incorruptable': 401,
 'dykes': 402,
 'pities': 403,
 'loaders': 405,
 'beauregard': 406,
 'fetishists': 414,
 'reputation': 408,
 'clovis': 409,
 'frequencies': 415,
 'bites': 411,
 'witherspoon': 412,
 'pastand': 24727,
 'camion': 416,
 'cristies': 417,
 'mirage': 24731,
 'sporatically': 61843,
 'questmaster': 419,
 'deputize': 420,
 'broke': 19606,
 'bwainn': 421,
 'guerin': 71,
 'coleen': 422,
 'krimis': 423,
 'whoppers': 425,
 'soapy': 72,
 'montalban': 426,
 'lumbering': 427,
 'strolled': 428,
 'tens': 429,
 'altruistic': 12508,
 'lemuria': 430,
 'nutsack': 431,
 'hokier': 432,
 'author': 433,
 'adalbert': 434,
 'manica': 73795,
 'replied': 435,
 'reckless': 61846,
 'britney': 437,
 'dahm': 438,
 'freshener': 439,
 'vouch': 440,
 'imbreds': 442,
 'benefits': 62652,
 'curtiss': 443,
 'tweeness': 12512,
 'lynching': 444,
 'camembert': 447,
 'draub': 448,
 'zungia': 451,
 'seductive': 450,
 'domain': 12514,
 'muscels': 452,
 'pitbull': 69424,
 'shifty': 453,
 'rearrange': 454,
 'mayne': 455,
 'modulating': 456,
 'gandhi': 457,
 'mattered': 72920,
 'overcranked': 458,
 'baptist': 459,
 'stinko': 460,
 'impersonating': 463,
 'mixers': 464,
 'cathay': 69679,
 'finite': 465,
 'spreads': 24725,
 'ambigious': 466,
 'squirmish': 468,
 'wreck': 469,
 'cathartic': 470,
 'penn': 472,
 'spanning': 475,
 'extremal': 63270,
 'doenitz': 476,
 'commandant': 477,
 'gunshots': 478,
 'gourgous': 24740,
 'mesa': 49573,
 'constabulary': 479,
 'mesmorizingly': 480,
 'lipgloss': 485,
 'pykes': 482,
 'demagogue': 484,
 'last': 37194,
 'avenger': 486,
 'unhackneyed': 61853,
 'columbian': 37196,
 'minka': 487,
 'blodwyn': 488,
 'charges': 489,
 'rad': 490,
 'affiliation': 491,
 'jefferey': 492,
 'paramedics': 37197,
 'imperial': 493,
 'scoured': 494,
 'nueve': 495,
 'corrupted': 496,
 'obviusly': 497,
 'toped': 498,
 'rednecks': 61072,
 'disorderly': 500,
 'review': 501,
 'misleadingly': 502,
 'loui': 503,
 'design': 49577,
 'summertime': 504,
 'rove': 61857,
 'refreshed': 505,
 'richly': 2169,
 'thomp': 83,
 'heralds': 507,
 'squirmishness': 508,
 'bucharest': 510,
 'czechs': 511,
 'worsened': 513,
 'consume': 52026,
 'territories': 27516,
 'himesh': 514,
 'upgrade': 516,
 'television': 517,
 'portentous': 59269,
 'censor': 49038,
 'meres': 518,
 'cletus': 519,
 'stk': 522,
 'bludgeon': 521,
 'laced': 523,
 'adamantly': 527,
 'convert': 525,
 'aforesaid': 528,
 'sprog': 530,
 'elements': 531,
 'rustbelt': 532,
 'pagels': 534,
 'gyllenhaal': 73264,
 'frolics': 40977,
 'divison': 535,
 'charasmatic': 536,
 'mn': 538,
 'booooooo': 37203,
 'lain': 70991,
 'pallette': 539,
 'aciton': 542,
 'incompatible': 541,
 'irrelevancy': 543,
 'reba': 544,
 'fenced': 18950,
 'finishers': 37207,
 'giovanni': 546,
 'diverged': 24752,
 'petulant': 547,
 'alluded': 549,
 'discus': 553,
 'fischer': 552,
 'towner': 555,
 'eta': 558,
 'zedora': 557,
 'scar': 61868,
 'byner': 560,
 'hazed': 561,
 'luchini': 12531,
 'starring': 92,
 'rovner': 563,
 'preform': 564,
 'juncos': 97,
 'seince': 565,
 'townfolks': 53946,
 'prowling': 566,
 'hello': 567,
 'accept': 568,
 'si': 570,
 'gourmets': 571,
 'beane': 61871,
 'photogenic': 572,
 'redmon': 573,
 'vovchenko': 574,
 'greener': 575,
 'coloured': 576,
 'frenches': 61888,
 'jd': 577,
 'underestimation': 578,
 'uninterested': 580,
 'savanna': 581,
 'essanay': 582,
 'tnn': 583,
 'minoan': 584,
 'konishita': 585,
 'forests': 586,
 'infirmed': 37217,
 'inciteful': 72964,
 'juxtaposition': 587,
 'bowen': 588,
 'sanjay': 589,
 'tarzans': 61874,
 'coolest': 25551,
 'tinker': 591,
 'modify': 592,
 'thunders': 593,
 'goalposts': 594,
 'zilcho': 596,
 'chesterton': 597,
 'luthercorp': 600,
 'quigon': 101,
 'champagne': 602,
 'transparency': 603,
 'schneerbaum': 12539,
 'claustrophobic': 66355,
 'pixies': 604,
 'dirs': 606,
 'linklaters': 61878,
 'pushed': 607,
 'cap': 609,
 'things': 610,
 'taste': 611,
 'earphones': 614,
 'tragic': 615,
 'upped': 26478,
 'oppressed': 616,
 'emigr': 620,
 'monstrosity': 621,
 'quicktime': 622,
 'sharkboy': 625,
 'innit': 627,
 'alternates': 628,
 'idealist': 630,
 'barbarash': 632,
 'glo': 633,
 'lessor': 634,
 'mciver': 105,
 'toland': 636,
 'todos': 62208,
 'toffee': 637,
 'chvez': 638,
 'unrecognizable': 643,
 'tsars': 640,
 'homogeneous': 644,
 'spinola': 648,
 'crudest': 61886,
 'paleolithic': 645,
 'feces': 646,
 'gershuni': 647,
 'miser': 649,
 'else': 650,
 'saitn': 653,
 'tsu': 49602,
 'hollwood': 654,
 'neese': 658,
 'inveterate': 656,
 'captivating': 657,
 'bruce': 37228,
 'jake': 659,
 'vincenzo': 660,
 'fakes': 68670,
 'loopholes': 661,
 'cynical': 662,
 'rayguns': 663,
 'complications': 37230,
 'resourceful': 664,
 'alleyways': 665,
 'morgus': 671,
 'coeds': 668,
 'ludivine': 670,
 'fontana': 672,
 'richardson': 37231,
 'hippy': 50838,
 'krazy': 673,
 'luis': 68835,
 'audry': 65872,
 'ahamad': 46586,
 'lelliott': 674,
 'tenuta': 675,
 'scorer': 56997,
 'defend': 49607,
 'caldwell': 676,
 'cereal': 677,
 'percussion': 680,
 'pecos': 681,
 'critiqued': 112,
 'harf': 682,
 'cerebral': 683,
 'weld': 684,
 'koyaanisqatsi': 685,
 'crustacean': 687,
 'ramme': 688,
 'nighttime': 689,
 'delineate': 690,
 'artyfartyrati': 61897,
 'barnaby': 691,
 'curiousity': 55049,
 'credibilty': 693,
 'fitzs': 694,
 'disappointmented': 695,
 'geisha': 696,
 'adventists': 61899,
 'spheres': 697,
 'dichen': 54703,
 'magneto': 698,
 'dwar': 24771,
 'midler': 700,
 'stoichastic': 701,
 'crappest': 702,
 'bloomsday': 703,
 'ribcage': 705,
 'primo': 706,
 'mutates': 707,
 'cubbi': 708,
 'persepctive': 49615,
 'monette': 710,
 'kollos': 711,
 'accuracy': 712,
 'bathtubs': 713,
 'fav': 715,
 'contagonists': 716,
 'talkier': 717,
 'ifpi': 718,
 'cornelia': 719,
 'lazar': 720,
 'manoven': 721,
 'redifined': 61905,
 'heckled': 725,
 'receptions': 723,
 'licking': 724,
 'especiallly': 726,
 'lapse': 727,
 'hantz': 729,
 'habit': 66431,
 'omfg': 121,
 'excempt': 731,
 'sarsgaard': 733,
 'threat': 734,
 'jarols': 737,
 'archipelago': 24783,
 'unalluring': 71386,
 'pengiun': 739,
 'fangoria': 744,
 'els': 742,
 'faccia': 73355,
 'us': 745,
 'alongno': 37244,
 'debussy': 61907,
 'phisique': 747,
 'slopped': 748,
 'rumbles': 749,
 'bailout': 750,
 'unowns': 63412,
 'physician': 752,
 'sideshows': 69464,
 'alexandra': 52182,
 'extensions': 754,
 'chewer': 758,
 'parachute': 757,
 'storyline': 49619,
 'earliest': 759,
 'bluegrass': 760,
 'menjou': 61912,
 'distortion': 761,
 'reception': 762,
 'aubrey': 37248,
 'linchpins': 763,
 'schlitz': 25177,
 'reclamation': 32720,
 'enrapture': 765,
 'ebert': 767,
 'repudiate': 768,
 'tattersall': 769,
 'negotiating': 770,
 'hddcs': 772,
 'slums': 773,
 'ascended': 774,
 'annna': 12558,
 'divine': 775,
 'gleam': 71172,
 'bambaataa': 61914,
 'delight': 776,
 'parslow': 778,
 'comedies': 779,
 'disagreeing': 780,
 'printer': 781,
 'costy': 783,
 'wyne': 784,
 'genital': 58115,
 'zink': 61916,
 'ludlow': 785,
 'beeb': 43691,
 'elga': 786,
 'coolness': 787,
 'dorfman': 788,
 'mcfarland': 51382,
 'mantra': 789,
 'imploring': 65271,
 'von': 790,
 'dervish': 791,
 'clment': 793,
 'nanavati': 794,
 'melato': 796,
 'univesity': 797,
 'keeranor': 59516,
 'supermans': 799,
 'moronfest': 801,
 'amongst': 802,
 'priestly': 803,
 'potently': 61922,
 'sarongs': 804,
 'rumble': 805,
 'caleb': 808,
 'bulk': 807,
 'vulnerabilities': 817,
 'cannes': 816,
 'cutsey': 811,
 'ginny': 67449,
 'sift': 813,
 'imzadi': 815,
 'fairview': 819,
 'significance': 820,
 'emmerdale': 822,
 'yubb': 824,
 'shipwreck': 825,
 'kilometers': 826,
 'exasperates': 827,
 'motorised': 828,
 'cavewoman': 12568,
 'cassio': 829,
 'dishonorable': 830,
 'hanging': 831,
 'characterless': 44476,
 'amusedly': 61928,
 'gloated': 832,
 'undoes': 833,
 'maharashtra': 834,
 'concentrated': 835,
 'ettore': 838,
 'oftentimes': 839,
 'representatives': 840,
 'bethune': 841,
 'contour': 843,
 'lita': 844,
 'huntingdon': 845,
 'shrubs': 846,
 'wail': 848,
 'barnes': 67293,
 'astonishingly': 849,
 'estupidos': 850,
 'bte': 852,
 'glare': 853,
 'analyzer': 854,
 'screenacting': 855,
 'borkowski': 857,
 'reflect': 858,
 'aed': 859,
 'foreclosed': 860,
 'sobbingly': 861,
 'skating': 862,
 'eiffel': 863,
 'scoffing': 864,
 'escargot': 865,
 'unshakeable': 866,
 'dysfunctional': 867,
 'cringing': 868,
 'cook': 41044,
 'overviews': 869,
 'sphincters': 870,
 'bewitching': 14172,
 'd': 871,
 'vip': 24799,
 'captain': 872,
 'commentating': 873,
 'lakehurst': 145,
 'egomaniacal': 874,
 'keena': 877,
 'homesteading': 876,
 'yey': 878,
 'theid': 879,
 'kemble': 880,
 'dreamcatcher': 885,
 'virginny': 882,
 'divides': 883,
 'tingle': 884,
 'splintering': 886,
 'extortion': 58353,
 'bbm': 72585,
 'clerks': 887,
 'spliting': 888,
 'clues': 889,
 'hoshi': 890,
 'draco': 891,
 'ingalls': 892,
 'prejudicm': 37267,
 'rouges': 893,
 'posturing': 894,
 'outlet': 49641,
 'heterosexuals': 21256,
 'subterfuge': 895,
 'fogbound': 24804,
 'monteith': 896,
 'tinseltown': 897,
 'talkin': 899,
 'overprotective': 900,
 'hesitancies': 151,
 'byproduct': 64358,
 'photochemical': 903,
 'shojo': 904,
 'diahnn': 906,
 'villaness': 69624,
 'snapped': 910,
 'kossack': 914,
 'stagnates': 909,
 'rvd': 911,
 'impersonalized': 912,
 'idle': 913,
 'squandering': 37273,
 'favoured': 61940,
 'duress': 915,
 'temmink': 73514,
 'vehicular': 3342,
 'cking': 917,
 'mongering': 918,
 'berton': 919,
 'murdstone': 27132,
 'rostotsky': 64800,
 'squeals': 37275,
 'naturalized': 920,
 'htm': 921,
 'homoeroticisms': 926,
 'creamery': 923,
 'keoma': 924,
 'welle': 925,
 'cowritten': 60466,
 'joker': 47824,
 'leaps': 12582,
 'misconstrue': 927,
 'educative': 929,
 'pensaba': 935,
 'starfucker': 931,
 'expressionistic': 932,
 'regalbuto': 933,
 'shooting': 934,
 'fatalism': 49650,
 'pillow': 938,
 'stabs': 939,
 'adjoining': 49655,
 'moviewise': 940,
 'modernisation': 38847,
 'reardon': 941,
 'canvasing': 942,
 'scarsely': 944,
 'prescence': 945,
 'philadelphia': 946,
 'amilee': 947,
 'congress': 948,
 'greuesome': 949,
 'glut': 950,
 'vodka': 952,
 'wink': 955,
 'toas': 954,
 'perfetta': 956,
 'incidentals': 957,
 'silverstonesque': 24810,
 'yello': 69628,
 'bissell': 66081,
 'yankland': 959,
 'therapists': 962,
 'exuded': 961,
 'shittttttttttttttty': 965,
 'masculine': 964,
 'oedpius': 972,
 'shreveport': 968,
 'gingernuts': 6885,
 'politique': 970,
 'unnerved': 971,
 'abrasively': 973,
 'enterprise': 974,
 'bulky': 975,
 'haplessly': 977,
 'testament': 12590,
 'klimt': 978,
 'cleaned': 979,
 'rashly': 981,
 'mentalist': 983,
 'lul': 24814,
 'toth': 12592,
 'unforgettable': 67848,
 'mainstay': 984,
 'levered': 986,
 'luciferian': 987,
 'godlike': 988,
 'interestingly': 989,
 'bumptious': 990,
 'fatness': 37288,
 'tackle': 991,
 'tachiguishi': 992,
 'naqoyqatsi': 993,
 'ksm': 994,
 'transgenic': 995,
 'nibby': 996,
 'quatermains': 997,
 'cloyed': 998,
 'sterotypes': 37291,
 'delightful': 999,
 'futures': 1000,
 ...}

...and now we can use this new "word2index" dictionary to populate our input layer with the right 1s in the right places.


In [91]:
def update_input_layer(review):
    
    global layer_0
    
    # clear out previous state, reset the layer to be all 0s
    layer_0 *= 0
    for word in review.split(" "):
        layer_0[0][word2index[word]] = 1

update_input_layer(reviews[0])

In [92]:
layer_0


Out[92]:
array([[ 1.,  0.,  0., ...,  0.,  0.,  0.]])

Creating the Target Data

And now we want to do the same thing for our target predictions


In [93]:
def get_target_for_label(label):
    if(label == 'POSITIVE'):
        return 1
    else:
        return 0

In [94]:
get_target_for_label(labels[0])


Out[94]:
1

In [95]:
get_target_for_label(labels[1])


Out[95]:
0

Putting it all together in a Neural Network


In [96]:
from IPython.display import Image
Image(filename='sentiment_network_2.png')


Out[96]:

In [97]:
import time
import sys
import numpy as np

# Let's tweak our network from before to model these phenomena
class SentimentNetwork:
    def __init__(self, reviews,labels,hidden_nodes = 10, learning_rate = 0.1):
       
        np.random.seed(1)
    
        self.pre_process_data()
        
        self.init_network(len(self.review_vocab),hidden_nodes, 1, learning_rate)
        
        
    def pre_process_data(self):
        
        review_vocab = set()
        for review in reviews:
            for word in review.split(" "):
                review_vocab.add(word)
        self.review_vocab = list(review_vocab)
        
        label_vocab = set()
        for label in labels:
            label_vocab.add(label)
        
        self.label_vocab = list(label_vocab)
        
        self.review_vocab_size = len(self.review_vocab)
        self.label_vocab_size = len(self.label_vocab)
        
        self.word2index = {}
        for i, word in enumerate(self.review_vocab):
            self.word2index[word] = i
        
        self.label2index = {}
        for i, label in enumerate(self.label_vocab):
            self.label2index[label] = i
         
        
    def init_network(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
        # Set number of nodes in input, hidden and output layers.
        self.input_nodes = input_nodes
        self.hidden_nodes = hidden_nodes
        self.output_nodes = output_nodes

        # Initialize weights
        self.weights_0_1 = np.zeros((self.input_nodes,self.hidden_nodes))
    
        self.weights_1_2 = np.random.normal(0.0, self.output_nodes**-0.5, 
                                                (self.hidden_nodes, self.output_nodes))
        
        self.learning_rate = learning_rate
        
        self.layer_0 = np.zeros((1,input_nodes))
    
        
    def update_input_layer(self,review):

        # clear out previous state, reset the layer to be all 0s
        self.layer_0 *= 0
        for word in review.split(" "):
            if(word in self.word2index.keys()):
                self.layer_0[0][self.word2index[word]] = 1
                
    def get_target_for_label(self,label):
        if(label == 'POSITIVE'):
            return 1
        else:
            return 0
        
    def sigmoid(self,x):
        return 1 / (1 + np.exp(-x))
    
    
    def sigmoid_output_2_derivative(self,output):
        return output * (1 - output)
    
    def train(self, training_reviews, training_labels):
        
        assert(len(training_reviews) == len(training_labels))
        
        correct_so_far = 0
        
        start = time.time()
        
        for i in range(len(training_reviews)):
            
            review = training_reviews[i]
            label = training_labels[i]
            
            #### Implement the forward pass here ####
            ### Forward pass ###

            # Input Layer
            self.update_input_layer(review)

            # Hidden layer
            layer_1 = self.layer_0.dot(self.weights_0_1)

            # Output layer
            layer_2 = self.sigmoid(layer_1.dot(self.weights_1_2))

            #### Implement the backward pass here ####
            ### Backward pass ###

            # TODO: Output error
            layer_2_error = layer_2 - self.get_target_for_label(label) # Output layer error is the difference between desired target and actual output.
            layer_2_delta = layer_2_error * self.sigmoid_output_2_derivative(layer_2)

            # TODO: Backpropagated error
            layer_1_error = layer_2_delta.dot(self.weights_1_2.T) # errors propagated to the hidden layer
            layer_1_delta = layer_1_error # hidden layer gradients - no nonlinearity so it's the same as the error

            # TODO: Update the weights
            self.weights_1_2 -= layer_1.T.dot(layer_2_delta) * self.learning_rate # update hidden-to-output weights with gradient descent step
            self.weights_0_1 -= self.layer_0.T.dot(layer_1_delta) * self.learning_rate # update input-to-hidden weights with gradient descent step

            if(np.abs(layer_2_error) < 0.5):
                correct_so_far += 1
            
            reviews_per_second = i / float(time.time() - start)
            
            sys.stdout.write("\rProgress:" + str(100 * i/float(len(training_reviews)))[:4] + "% Speed(reviews/sec):" + str(reviews_per_second)[0:5] + " #Correct:" + str(correct_so_far) + " #Trained:" + str(i+1) + " Training Accuracy:" + str(correct_so_far * 100 / float(i+1))[:4] + "%")
        
    
    def test(self, testing_reviews, testing_labels):
        
        correct = 0
        
        start = time.time()
        
        for i in range(len(testing_reviews)):
            pred = self.run(testing_reviews[i])
            if(pred == testing_labels[i]):
                correct += 1
            
            reviews_per_second = i / float(time.time() - start)
            
            sys.stdout.write("\rProgress:" + str(100 * i/float(len(testing_reviews)))[:4] \
                             + "% Speed(reviews/sec):" + str(reviews_per_second)[0:5] \
                            + "% #Correct:" + str(correct) + " #Tested:" + str(i+1) + " Testing Accuracy:" + str(correct * 100 / float(i+1))[:4] + "%")
    
    def run(self, review):
        
        # Input Layer
        self.update_input_layer(review.lower())

        # Hidden layer
        layer_1 = self.layer_0.dot(self.weights_0_1)

        # Output layer
        layer_2 = self.sigmoid(layer_1.dot(self.weights_1_2))
        
        if(layer_2[0] > 0.5):
            return "POSITIVE"
        else:
            return "NEGATIVE"

In [98]:
mlp = SentimentNetwork(reviews[:-1000],labels[:-1000])

In [99]:
# evaluate our model before training (just to show how horrible it is)
mlp.test(reviews[-1000:],labels[-1000:])


Progress:99.9% Speed(reviews/sec):759.4% #Correct:500 #Tested:1000 Testing Accuracy:50.0%

In [100]:
# train the network
mlp.train(reviews[:-1000],labels[:-1000])


Progress:99.9% Speed(reviews/sec):114.8 #Correct:20136 #Trained:24000 Training Accuracy:83.9%

In [101]:
# evaluate the model after training
mlp.test(reviews[-1000:],labels[-1000:])


Progress:99.9% Speed(reviews/sec):774.6% #Correct:852 #Tested:1000 Testing Accuracy:85.2%

In [102]:
mlp.run("That movie was great")


Out[102]:
'POSITIVE'

Making our Network Train and Run Faster

Even though this network is very trainable on a laptop, we can really get a lot more performance out of it, and doing so is all about understanding how the neural network is interacting with our data (again, "modeling the problem"). Let's take a moment to consider how layer_1 is generated. First, we're going to create a smaller layer_0 so that we can easily picture all the values in our notebook.


In [103]:
layer_0 = np.zeros(10)

In [104]:
layer_0


Out[104]:
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

Now, let's set a few of the inputs to 1s, and create a sample weight matrix


In [105]:
layer_0[4] = 1
layer_0[9] = 1
layer_0


Out[105]:
array([ 0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  1.])

In [106]:
weights_0_1 = np.random.randn(10,5)

So, given these pieces, layer_1 is created in the following way....


In [107]:
layer_1 = layer_0.dot(weights_0_1)

In [108]:
layer_1


Out[108]:
array([-0.10503756,  0.44222989,  0.24392938, -0.55961832,  0.21389503])

layer_1 is generated by performing vector->matrix multiplication, however, most of our input neurons are turned off! Thus, there's actually a lot of computation being wasted. Consider the network below.


In [109]:
Image(filename='sentiment_network_sparse.png')


Out[109]:

First Inefficiency: "0" neurons waste computation

If you recall from previous lessons, each edge from one neuron to another represents a single value in our weights_0_1 matrix. When we forward propagate, we take our input neuron's value, multiply it by each weight attached to that neuron, and then sum all the resulting values in the next layer. So, in this case, if only "excellent" was turned on, then all of the multiplications comein gout of "horrible" and "terrible" are wasted computation! All of the weights coming out of "horrible" and "terrible" are being multiplied by 0, thus having no affect on our values in layer_1.


In [110]:
Image(filename='sentiment_network_sparse_2.png')


Out[110]:

Second Inefficiency: "1" neurons don't need to multiply!

When we're forward propagating, we multiply our input neuron's value by the weights attached to it. However, in this case, when the neuron is turned on, it's always turned on to exactly 1. So, there's no need for multiplication, what if we skipped this step?

The Solution: Create layer_1 by adding the vectors for each word.

Instead of generating a huge layer_0 vector and then performing a full vector->matrix multiplication across our huge weights_0_1 matrix, we can simply sum the rows of weights_0_1 that correspond to the words in our review. The resulting value of layer_1 will be exactly the same as if we had performed a full matrix multiplication at a fraction of the computational cost. This is called a "lookup table" or an "embedding layer".


In [111]:
#inefficient thing we did before

layer_1 = layer_0.dot(weights_0_1)
layer_1


Out[111]:
array([-0.10503756,  0.44222989,  0.24392938, -0.55961832,  0.21389503])

In [112]:
# new, less expensive lookup table version

layer_1 = weights_0_1[4] + weights_0_1[9]
layer_1


Out[112]:
array([-0.10503756,  0.44222989,  0.24392938, -0.55961832,  0.21389503])

See how they generate exactly the same value? Let's update our new neural network to do this.


In [397]:
import time
import sys

# Let's tweak our network from before to model these phenomena
class SentimentNetwork:
    def __init__(self, reviews,labels,hidden_nodes = 10, learning_rate = 0.1):
       
        np.random.seed(1)
    
        self.pre_process_data(reviews)
        
        self.init_network(len(self.review_vocab),hidden_nodes, 1, learning_rate)
        
        
    def pre_process_data(self,reviews):
        
        review_vocab = set()
        for review in reviews:
            for word in review.split(" "):
                review_vocab.add(word)
        self.review_vocab = list(review_vocab)
        
        label_vocab = set()
        for label in labels:
            label_vocab.add(label)
        
        self.label_vocab = list(label_vocab)
        
        self.review_vocab_size = len(self.review_vocab)
        self.label_vocab_size = len(self.label_vocab)
        
        self.word2index = {}
        for i, word in enumerate(self.review_vocab):
            self.word2index[word] = i
        
        self.label2index = {}
        for i, label in enumerate(self.label_vocab):
            self.label2index[label] = i
         
        
    def init_network(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
        # Set number of nodes in input, hidden and output layers.
        self.input_nodes = input_nodes
        self.hidden_nodes = hidden_nodes
        self.output_nodes = output_nodes

        # Initialize weights
        self.weights_0_1 = np.zeros((self.input_nodes,self.hidden_nodes))
    
        self.weights_1_2 = np.random.normal(0.0, self.output_nodes**-0.5, 
                                                (self.hidden_nodes, self.output_nodes))
        
        self.learning_rate = learning_rate
        
        self.layer_0 = np.zeros((1,input_nodes))
        self.layer_1 = np.zeros((1,hidden_nodes))
        
    def sigmoid(self,x):
        return 1 / (1 + np.exp(-x))
    
    
    def sigmoid_output_2_derivative(self,output):
        return output * (1 - output)
    
    def update_input_layer(self,review):

        # clear out previous state, reset the layer to be all 0s
        self.layer_0 *= 0
        for word in review.split(" "):
            self.layer_0[0][self.word2index[word]] = 1

    def get_target_for_label(self,label):
        if(label == 'POSITIVE'):
            return 1
        else:
            return 0
        
    def train(self, training_reviews_raw, training_labels):
        
        training_reviews = list()
        for review in training_reviews_raw:
            indices = set()
            for word in review.split(" "):
                if(word in self.word2index.keys()):
                    indices.add(self.word2index[word])
            training_reviews.append(list(indices))
        
        assert(len(training_reviews) == len(training_labels))
        
        correct_so_far = 0
        
        start = time.time()
        
        for i in range(len(training_reviews)):
            
            review = training_reviews[i]
            label = training_labels[i]
            
            #### Implement the forward pass here ####
            ### Forward pass ###

            # Input Layer

            # Hidden layer
#             layer_1 = self.layer_0.dot(self.weights_0_1)
            self.layer_1 *= 0
            for index in review:
                self.layer_1 += self.weights_0_1[index]
            
            # Output layer
            layer_2 = self.sigmoid(self.layer_1.dot(self.weights_1_2))

            #### Implement the backward pass here ####
            ### Backward pass ###

            # Output error
            layer_2_error = layer_2 - self.get_target_for_label(label) # Output layer error is the difference between desired target and actual output.
            layer_2_delta = layer_2_error * self.sigmoid_output_2_derivative(layer_2)

            # Backpropagated error
            layer_1_error = layer_2_delta.dot(self.weights_1_2.T) # errors propagated to the hidden layer
            layer_1_delta = layer_1_error # hidden layer gradients - no nonlinearity so it's the same as the error

            # Update the weights
            self.weights_1_2 -= self.layer_1.T.dot(layer_2_delta) * self.learning_rate # update hidden-to-output weights with gradient descent step
            
            for index in review:
                self.weights_0_1[index] -= layer_1_delta[0] * self.learning_rate # update input-to-hidden weights with gradient descent step

            if(np.abs(layer_2_error) < 0.5):
                correct_so_far += 1
            
            reviews_per_second = i / float(time.time() - start)
            
            sys.stdout.write("\rProgress:" + str(100 * i/float(len(training_reviews)))[:4] + "% Speed(reviews/sec):" + str(reviews_per_second)[0:5] + " #Correct:" + str(correct_so_far) + " #Trained:" + str(i+1) + " Training Accuracy:" + str(correct_so_far * 100 / float(i+1))[:4] + "%")
        
    
    def test(self, testing_reviews, testing_labels):
        
        correct = 0
        
        start = time.time()
        
        for i in range(len(testing_reviews)):
            pred = self.run(testing_reviews[i])
            if(pred == testing_labels[i]):
                correct += 1
            
            reviews_per_second = i / float(time.time() - start)
            
            sys.stdout.write("\rProgress:" + str(100 * i/float(len(testing_reviews)))[:4] \
                             + "% Speed(reviews/sec):" + str(reviews_per_second)[0:5] \
                            + "% #Correct:" + str(correct) + " #Tested:" + str(i+1) + " Testing Accuracy:" + str(correct * 100 / float(i+1))[:4] + "%")
    
    def run(self, review):
        
        # Input Layer


        # Hidden layer
        self.layer_1 *= 0
        unique_indices = set()
        for word in review.lower().split(" "):
            if word in self.word2index.keys():
                unique_indices.add(self.word2index[word])
        for index in unique_indices:
            self.layer_1 += self.weights_0_1[index]
        
        # Output layer
        layer_2 = self.sigmoid(self.layer_1.dot(self.weights_1_2))
        
        if(layer_2[0] > 0.5):
            return "POSITIVE"
        else:
            return "NEGATIVE"

In [398]:
mlp = SentimentNetwork(reviews[:-1000],labels[:-1000],learning_rate=0.01)

In [399]:
# train the network
mlp.train(reviews[:-1000],labels[:-1000])


Progress:99.9% Speed(reviews/sec):1495. #Correct:20334 #Trained:24000 Training Accuracy:84.7%

And wallah! Our network learns 10x faster than before while making exactly the same predictions!


In [400]:
# evaluate our model before training (just to show how horrible it is)
mlp.test(reviews[-1000:],labels[-1000:])


Progress:99.9% Speed(reviews/sec):2119.% #Correct:856 #Tested:1000 Testing Accuracy:85.6%

Our network even tests over twice as fast as well!


In [ ]:

Making Learning Faster & Easier by Reducing Noise

So at first this might seem like the same thing we did in the previous section. However, while the previous section was about looking for computational waste and triming it out, this section is about looking for noise in our data and trimming it out. When we reduce the "noise" in our data, the neural network can identify correlation must faster and with greater accuracy. Whereas our technique will be simple, many recently developed state-of-the-art techniques (most notably attention and batch normalization) are all about reducing the amount of noise that your network has to filter through. The more obvious you can make the correaltion to your neural network, the better.

Our network is looking for correlation between movie review vocabularies and output positive/negative labels. In order to do this, our network has to come to understand over 70,000 different words in our vocabulary! That's a ton of knowledge that the network has to learn!

This begs the questions, are all the words in the vocabulary actually relevant to sentiment? A few pages ago, we counted how often words occured in positive reviews relative to negative reviews and created a ratio. We could then sort words by this ratio and see the words with the most positive and negative affinity. If you remember, the output looked like this:


In [150]:
# words most frequently seen in a review with a "POSITIVE" label
pos_neg_ratios.most_common()


Out[150]:
[('edie', 4.6913478822291435),
 ('paulie', 4.0775374439057197),
 ('felix', 3.1527360223636558),
 ('polanski', 2.8233610476132043),
 ('matthau', 2.8067217286092401),
 ('victoria', 2.6810215287142909),
 ('mildred', 2.6026896854443837),
 ('gandhi', 2.5389738710582761),
 ('flawless', 2.451005098112319),
 ('superbly', 2.2600254785752498),
 ('perfection', 2.1594842493533721),
 ('astaire', 2.1400661634962708),
 ('captures', 2.0386195471595809),
 ('voight', 2.0301704926730531),
 ('wonderfully', 2.0218960560332353),
 ('powell', 1.9783454248084671),
 ('brosnan', 1.9547990964725592),
 ('lily', 1.9203768470501485),
 ('bakshi', 1.9029851043382795),
 ('lincoln', 1.9014583864844796),
 ('refreshing', 1.8551812956655511),
 ('breathtaking', 1.8481124057791867),
 ('bourne', 1.8478489358790986),
 ('lemmon', 1.8458266904983307),
 ('delightful', 1.8002701588959635),
 ('flynn', 1.7996646487351682),
 ('andrews', 1.7764919970972666),
 ('homer', 1.7692866133759964),
 ('beautifully', 1.7626953362841438),
 ('soccer', 1.7578579175523736),
 ('elvira', 1.7397031072720019),
 ('underrated', 1.7197859696029656),
 ('gripping', 1.7165360479904674),
 ('superb', 1.7091514458966952),
 ('delight', 1.6714733033535532),
 ('welles', 1.6677068205580761),
 ('sadness', 1.663505133704376),
 ('sinatra', 1.6389967146756448),
 ('touching', 1.637217476541176),
 ('timeless', 1.62924053973028),
 ('macy', 1.6211339521972916),
 ('unforgettable', 1.6177367152487956),
 ('favorites', 1.6158688027643908),
 ('stewart', 1.6119987332957739),
 ('sullivan', 1.6094379124341003),
 ('extraordinary', 1.6094379124341003),
 ('hartley', 1.6094379124341003),
 ('brilliantly', 1.5950491749820008),
 ('friendship', 1.5677652160335325),
 ('wonderful', 1.5645425925262093),
 ('palma', 1.5553706911638245),
 ('magnificent', 1.54663701119507),
 ('finest', 1.5462590108125689),
 ('jackie', 1.5439233053234738),
 ('ritter', 1.5404450409471491),
 ('tremendous', 1.5184661342283736),
 ('freedom', 1.5091151908062312),
 ('fantastic', 1.5048433868558566),
 ('terrific', 1.5026699370083942),
 ('noir', 1.493925025312256),
 ('sidney', 1.493925025312256),
 ('outstanding', 1.4910053152089213),
 ('mann', 1.4894785973551214),
 ('pleasantly', 1.4894785973551214),
 ('nancy', 1.488077055429833),
 ('marie', 1.4825711915553104),
 ('marvelous', 1.4739999415389962),
 ('excellent', 1.4647538505723599),
 ('ruth', 1.4596256342054401),
 ('stanwyck', 1.4412101187160054),
 ('widmark', 1.4350845252893227),
 ('splendid', 1.4271163556401458),
 ('chan', 1.423108334242607),
 ('exceptional', 1.4201959127955721),
 ('tender', 1.410986973710262),
 ('gentle', 1.4078005663408544),
 ('poignant', 1.4022947024663317),
 ('gem', 1.3932148039644643),
 ('amazing', 1.3919815802404802),
 ('chilling', 1.3862943611198906),
 ('captivating', 1.3862943611198906),
 ('davies', 1.3862943611198906),
 ('fisher', 1.3862943611198906),
 ('darker', 1.3652409519220583),
 ('april', 1.3499267169490159),
 ('kelly', 1.3461743673304654),
 ('blake', 1.3418425985490567),
 ('overlooked', 1.329135947279942),
 ('ralph', 1.32818673031261),
 ('bette', 1.3156767939059373),
 ('hoffman', 1.3150668518315229),
 ('cole', 1.3121863889661687),
 ('shines', 1.3049487216659381),
 ('powerful', 1.2999662776313934),
 ('notch', 1.2950456896547455),
 ('remarkable', 1.2883688239495823),
 ('pitt', 1.286210902562908),
 ('winters', 1.2833463918674481),
 ('vivid', 1.2762934659055623),
 ('gritty', 1.2757524867200667),
 ('giallo', 1.2745029551317739),
 ('portrait', 1.2704625455947689),
 ('innocence', 1.2694300209805796),
 ('psychiatrist', 1.2685113254635072),
 ('favorite', 1.2668956297860055),
 ('ensemble', 1.2656663733312759),
 ('stunning', 1.2622417124499117),
 ('burns', 1.259880436264232),
 ('garbo', 1.258954938743289),
 ('barbara', 1.2580400255962119),
 ('philip', 1.2527629684953681),
 ('holly', 1.2527629684953681),
 ('panic', 1.2527629684953681),
 ('carol', 1.2481440226390734),
 ('perfect', 1.246742480713785),
 ('appreciated', 1.2462482874741743),
 ('favourite', 1.2411123512753928),
 ('journey', 1.2367626271489269),
 ('rural', 1.235471471385307),
 ('bond', 1.2321436812926323),
 ('builds', 1.2305398317106577),
 ('brilliant', 1.2287554137664785),
 ('brooklyn', 1.2286654169163074),
 ('von', 1.225175011976539),
 ('unfolds', 1.2163953243244932),
 ('recommended', 1.2163953243244932),
 ('daniel', 1.20215296760895),
 ('perfectly', 1.1971931173405572),
 ('crafted', 1.1962507582320256),
 ('prince', 1.1939224684724346),
 ('troubled', 1.192138346678933),
 ('consequences', 1.1865810616140668),
 ('haunting', 1.1814999484738773),
 ('cinderella', 1.180052620608284),
 ('alexander', 1.1759989522835299),
 ('emotions', 1.1753049094563641),
 ('boxing', 1.1735135968412274),
 ('subtle', 1.1734135017508081),
 ('curtis', 1.1649873576129823),
 ('rare', 1.1566438362402944),
 ('loved', 1.1563661500586044),
 ('daughters', 1.1526795099383853),
 ('courage', 1.1438688802562305),
 ('dentist', 1.1426722784621401),
 ('highly', 1.1420208631618658),
 ('nominated', 1.1409146683587992),
 ('tony', 1.1397491942285991),
 ('draws', 1.1325138403437911),
 ('everyday', 1.1306150197542835),
 ('contrast', 1.1284652518177909),
 ('cried', 1.1213405397456659),
 ('fabulous', 1.1210851445201684),
 ('ned', 1.120591195386885),
 ('fay', 1.120591195386885),
 ('emma', 1.1184149159642893),
 ('sensitive', 1.113318436057805),
 ('smooth', 1.1089750757036563),
 ('dramas', 1.1080910326226534),
 ('today', 1.1050431789984001),
 ('helps', 1.1023091505494358),
 ('inspiring', 1.0986122886681098),
 ('jimmy', 1.0937696641923216),
 ('awesome', 1.0931328229034842),
 ('unique', 1.0881409888008142),
 ('tragic', 1.0871835928444868),
 ('intense', 1.0870514662670339),
 ('stellar', 1.0857088838322018),
 ('rival', 1.0822184788924332),
 ('provides', 1.0797081340289569),
 ('depression', 1.0782034170369026),
 ('shy', 1.0775588794702773),
 ('carrie', 1.076139432816051),
 ('blend', 1.0753554265038423),
 ('hank', 1.0736109864626924),
 ('diana', 1.0726368022648489),
 ('adorable', 1.0726368022648489),
 ('unexpected', 1.0722255334949147),
 ('achievement', 1.0668635903535293),
 ('bettie', 1.0663514264498881),
 ('happiness', 1.0632729222228008),
 ('glorious', 1.0608719606852626),
 ('davis', 1.0541605260972757),
 ('terrifying', 1.0525211814678428),
 ('beauty', 1.050410186850232),
 ('ideal', 1.0479685558493548),
 ('fears', 1.0467872208035236),
 ('hong', 1.0438040521731147),
 ('seasons', 1.0433496099930604),
 ('fascinating', 1.0414538748281612),
 ('carries', 1.0345904299031787),
 ('satisfying', 1.0321225473992768),
 ('definite', 1.0319209141694374),
 ('touched', 1.0296194171811581),
 ('greatest', 1.0248947127715422),
 ('creates', 1.0241097613701886),
 ('aunt', 1.023388867430522),
 ('walter', 1.022328983918479),
 ('spectacular', 1.0198314108149955),
 ('portrayal', 1.0189810189761024),
 ('ann', 1.0127808528183286),
 ('enterprise', 1.0116009116784799),
 ('musicals', 1.0096648026516135),
 ('deeply', 1.0094845087721023),
 ('incredible', 1.0061677561461084),
 ('mature', 1.0060195018402847),
 ('triumph', 0.99682959435816731),
 ('margaret', 0.99682959435816731),
 ('navy', 0.99493385919326827),
 ('harry', 0.99176919305006062),
 ('lucas', 0.990398704027877),
 ('sweet', 0.98966110487955483),
 ('joey', 0.98794672078059009),
 ('oscar', 0.98721905111049713),
 ('balance', 0.98649499054740353),
 ('warm', 0.98485340331145166),
 ('ages', 0.98449898190068863),
 ('carrey', 0.98082925301172619),
 ('glover', 0.98082925301172619),
 ('guilt', 0.98082925301172619),
 ('learns', 0.97881108885548895),
 ('unusual', 0.97788374278196932),
 ('sons', 0.97777581552483595),
 ('complex', 0.97761897738147796),
 ('essence', 0.97753435711487369),
 ('brazil', 0.9769153536905899),
 ('widow', 0.97650959186720987),
 ('solid', 0.97537964824416146),
 ('beautiful', 0.97326301262841053),
 ('holmes', 0.97246100334120955),
 ('awe', 0.97186058302896583),
 ('vhs', 0.97116734209998934),
 ('eerie', 0.97116734209998934),
 ('lonely', 0.96873720724669754),
 ('grim', 0.96873720724669754),
 ('sport', 0.96825047080486615),
 ('debut', 0.96508089604358704),
 ('destiny', 0.96343751029985703),
 ('thrillers', 0.96281074750904794),
 ('tears', 0.95977584381389391),
 ('rose', 0.95664202739772253),
 ('feelings', 0.95551144502743635),
 ('ginger', 0.95551144502743635),
 ('winning', 0.95471810900804055),
 ('stanley', 0.95387344302319799),
 ('cox', 0.95343027882361187),
 ('paris', 0.95278479030472663),
 ('heart', 0.95238806924516806),
 ('hooked', 0.95155887071161305),
 ('comfortable', 0.94803943018873538),
 ('mgm', 0.94446160884085151),
 ('masterpiece', 0.94155039863339296),
 ('themes', 0.94118828349588235),
 ('danny', 0.93967118051821874),
 ('anime', 0.93378388932167222),
 ('perry', 0.93328830824272613),
 ('joy', 0.93301752567946861),
 ('lovable', 0.93081883243706487),
 ('mysteries', 0.92953595862417571),
 ('hal', 0.92953595862417571),
 ('louis', 0.92871325187271225),
 ('charming', 0.92520609553210742),
 ('urban', 0.92367083917177761),
 ('allows', 0.92183091224977043),
 ('impact', 0.91815814604895041),
 ('italy', 0.91629073187415511),
 ('gradually', 0.91629073187415511),
 ('lifestyle', 0.91629073187415511),
 ('spy', 0.91289514287301687),
 ('treat', 0.91193342650519937),
 ('subsequent', 0.91056005716517008),
 ('kennedy', 0.90981821736853763),
 ('loving', 0.90967549275543591),
 ('surprising', 0.90937028902958128),
 ('quiet', 0.90648673177753425),
 ('winter', 0.90624039602065365),
 ('reveals', 0.90490540964902977),
 ('raw', 0.90445627422715225),
 ('funniest', 0.90078654533818991),
 ('norman', 0.89994159387262562),
 ('pleased', 0.89994159387262562),
 ('thief', 0.89874642222324552),
 ('season', 0.89827222637147675),
 ('secrets', 0.89794159320595857),
 ('colorful', 0.89705936994626756),
 ('highest', 0.8967461358011849),
 ('compelling', 0.89462923509297576),
 ('danes', 0.89248008318043659),
 ('castle', 0.88967708335606499),
 ('kudos', 0.88889175768604067),
 ('great', 0.88810470901464589),
 ('bleak', 0.88730319500090271),
 ('baseball', 0.88730319500090271),
 ('subtitles', 0.88730319500090271),
 ('winner', 0.88643776872447388),
 ('tragedy', 0.88563699078315261),
 ('todd', 0.88551907320740142),
 ('nicely', 0.87924946019380601),
 ('arthur', 0.87546873735389985),
 ('essential', 0.87373111745535925),
 ('gorgeous', 0.8731725250935497),
 ('fonda', 0.87294029100054127),
 ('eastwood', 0.87139541196626402),
 ('focuses', 0.87082835779739776),
 ('enjoyed', 0.87070195951624607),
 ('natural', 0.86997924506912838),
 ('intensity', 0.86835126958503595),
 ('witty', 0.86824103423244681),
 ('rob', 0.8642954367557748),
 ('worlds', 0.86377269759070874),
 ('health', 0.86113891179907498),
 ('magical', 0.85953791528170564),
 ('deeper', 0.85802182375017932),
 ('lucy', 0.85618680780444956),
 ('moving', 0.85566611005772031),
 ('lovely', 0.85290640004681306),
 ('purple', 0.8513711857748395),
 ('memorable', 0.84801189112086062),
 ('sings', 0.84729786038720367),
 ('modesty', 0.84342938360928321),
 ('craig', 0.84342938360928321),
 ('relate', 0.84326559685926517),
 ('episodes', 0.84223712084137292),
 ('strong', 0.84167135777060931),
 ('smith', 0.83959811108590054),
 ('tear', 0.83704136022001441),
 ('apartment', 0.83333115290549531),
 ('disagree', 0.83290912293510388),
 ('princess', 0.83290912293510388),
 ('kung', 0.83173334384609199),
 ('adventure', 0.83150561393278388),
 ('jake', 0.82667857318446791),
 ('columbo', 0.82667857318446791),
 ('adds', 0.82485652591452319),
 ('hart', 0.82472353834866463),
 ('strength', 0.82417544296634937),
 ('realizes', 0.82360006895738058),
 ('dave', 0.8232003088081431),
 ('childhood', 0.82208086393583857),
 ('forbidden', 0.81989888619908913),
 ('tight', 0.81883539572344199),
 ('surreal', 0.8178506590609026),
 ('manager', 0.81770990320170756),
 ('dancer', 0.81574950265227764),
 ('studios', 0.81093021621632877),
 ('con', 0.81093021621632877),
 ('miike', 0.80821651034473263),
 ('realistic', 0.80807714723392232),
 ('explicit', 0.80792269515237358),
 ('kurt', 0.8060875917405409),
 ('deals', 0.80535917116687328),
 ('traditional', 0.80535917116687328),
 ('holds', 0.80493858654806194),
 ('carl', 0.80437281567016972),
 ('touches', 0.80396154690023547),
 ('gene', 0.80314807577427383),
 ('albert', 0.8027669055771679),
 ('abc', 0.80234647252493729),
 ('cry', 0.80011930011211307),
 ('sides', 0.7995275841185171),
 ('develops', 0.79850769621777162),
 ('eyre', 0.79850769621777162),
 ('dances', 0.79694397424158891),
 ('oscars', 0.79633141679517616),
 ('legendary', 0.79600456599965308),
 ('importance', 0.79492987486988764),
 ('hearted', 0.79492987486988764),
 ('portraying', 0.79356592830699269),
 ('impressed', 0.79258107754813223),
 ('waters', 0.79112758892014912),
 ('empire', 0.79078565012386137),
 ('edge', 0.789774016249017),
 ('jean', 0.78845736036427028),
 ('environment', 0.78845736036427028),
 ('sentimental', 0.7864791203521645),
 ('captured', 0.78623760362595729),
 ('styles', 0.78592891401091158),
 ('daring', 0.78592891401091158),
 ('backgrounds', 0.78275933924963248),
 ('matches', 0.78275933924963248),
 ('tense', 0.78275933924963248),
 ('frank', 0.78275933924963248),
 ('gothic', 0.78209466657644144),
 ('sharp', 0.7814397877056235),
 ('achieved', 0.78015855754957497),
 ('court', 0.77947526404844247),
 ('steals', 0.7789140023173704),
 ('rules', 0.77844476107184035),
 ('colors', 0.77684619943659217),
 ('reunion', 0.77318988823348167),
 ('covers', 0.77139937745969345),
 ('tale', 0.77010822169607374),
 ('rain', 0.7683706017975328),
 ('denzel', 0.76804848873306297),
 ('stays', 0.76787072675588186),
 ('blob', 0.76725515271366718),
 ('conventional', 0.76214005204689672),
 ('maria', 0.76214005204689672),
 ('fresh', 0.76158434211317383),
 ('midnight', 0.76096977689870637),
 ('landscape', 0.75852993982279704),
 ('animated', 0.75768570169751648),
 ('sunday', 0.75666058628227129),
 ('titanic', 0.75666058628227129),
 ('cagney', 0.7537718023763802),
 ('spring', 0.7537718023763802),
 ('enjoyable', 0.75246375771636476),
 ('immensely', 0.75198768058287868),
 ('sir', 0.7507762933965817),
 ('nevertheless', 0.75067102469813185),
 ('driven', 0.74994477895307854),
 ('performances', 0.74883252516063137),
 ('nowadays', 0.74721440183022114),
 ('memories', 0.74721440183022114),
 ('simple', 0.74641420974143258),
 ('leslie', 0.74533293373051557),
 ('golden', 0.74533293373051557),
 ('lovers', 0.74497224842453125),
 ('relationship', 0.74484232345601786),
 ('supporting', 0.74357803418683721),
 ('che', 0.74262723782331497),
 ('packed', 0.7410032017375805),
 ('trek', 0.74021469141793106),
 ('provoking', 0.73840377214806618),
 ('strikes', 0.73759894313077912),
 ('depiction', 0.73682224406260699),
 ('emotional', 0.73678211645681524),
 ('secretary', 0.7366322924996842),
 ('influenced', 0.73511137965897755),
 ('florida', 0.73511137965897755),
 ('germany', 0.73288750920945944),
 ('brings', 0.73142936713096229),
 ('lewis', 0.73129894652432159),
 ('elderly', 0.73088750854279239),
 ('owner', 0.72743625403857748),
 ('streets', 0.72666987259858895),
 ('henry', 0.72642196944481741),
 ('portrays', 0.72593700338293632),
 ('bears', 0.7252354951114458),
 ('china', 0.72489587887452556),
 ('anger', 0.72439972406404984),
 ('society', 0.72433010799663333),
 ('available', 0.72415741730250549),
 ('best', 0.72347034060446314),
 ('bugs', 0.72270598280148979),
 ('magic', 0.71878961117328299),
 ('delivers', 0.71846498854423513),
 ('verhoeven', 0.71846498854423513),
 ('jim', 0.71783979315031676),
 ('donald', 0.71667767797013937),
 ('endearing', 0.71465338578090898),
 ('relationships', 0.71393795022901896),
 ('greatly', 0.71256526641704687),
 ('brad', 0.71024161391924534),
 ('charlie', 0.71024161391924534),
 ('simon', 0.70967648251115578),
 ('effectively', 0.70914752190638641),
 ('march', 0.70774597998109789),
 ('atmosphere', 0.70744773070214162),
 ('influence', 0.70733181555190172),
 ('genius', 0.706392407309966),
 ('emotionally', 0.70556970055850243),
 ('ken', 0.70526854109229009),
 ('identity', 0.70484322032313651),
 ('sophisticated', 0.70470800296102132),
 ('dan', 0.70457587638356811),
 ('andrew', 0.70329955202396321),
 ('india', 0.70144598337464037),
 ('roy', 0.69970458110610434),
 ('surprisingly', 0.6995780708902356),
 ('sky', 0.69780919366575667),
 ('romantic', 0.69664981111114743),
 ('match', 0.69566924999265523),
 ('bitter', 0.69314718055994529),
 ('wave', 0.69314718055994529),
 ('patient', 0.69314718055994529),
 ('beatty', 0.69314718055994529),
 ('britain', 0.69314718055994529),
 ('affected', 0.69314718055994529),
 ('cowboy', 0.69314718055994529),
 ('stylish', 0.69314718055994529),
 ('meets', 0.69314718055994529),
 ('love', 0.69198533541937324),
 ('paul', 0.68980827929443067),
 ('andy', 0.68846333124751902),
 ('performance', 0.68797386327972465),
 ('patrick', 0.68645819240914863),
 ('unlike', 0.68546468438792907),
 ('brooks', 0.68433655087779044),
 ('refuses', 0.68348526964820844),
 ('complaint', 0.6824518914431974),
 ('award', 0.6824518914431974),
 ('ride', 0.68229716453587952),
 ('dawson', 0.68171848473632257),
 ('luke', 0.68158635815886937),
 ('wells', 0.68087708796813096),
 ('france', 0.6804081547825156),
 ('handsome', 0.68007509899259255),
 ('sports', 0.68007509899259255),
 ('directs', 0.67875844310784572),
 ('rebel', 0.67875844310784572),
 ('greater', 0.67605274720064523),
 ('dreams', 0.67599410133369586),
 ('effective', 0.67565402311242806),
 ('interpretation', 0.67479804189174875),
 ('brando', 0.67445504754779284),
 ('works', 0.67445504754779284),
 ('noble', 0.6737290947028437),
 ('paced', 0.67314651385327573),
 ('le', 0.67067432470788668),
 ('master', 0.67015766233524654),
 ('h', 0.6696166831497512),
 ('rings', 0.66904962898088483),
 ('easy', 0.66895995494594152),
 ('city', 0.66820823221269321),
 ('sunshine', 0.66782937257565544),
 ('succeeds', 0.66647893347778397),
 ('relations', 0.664159643686693),
 ('england', 0.66387679825983203),
 ('glimpse', 0.66329421741026418),
 ('aired', 0.66268797307523675),
 ('sees', 0.66263163663399482),
 ('both', 0.66248336767382998),
 ('definitely', 0.66199789483898808),
 ('imaginative', 0.66139848224536502),
 ('appreciate', 0.66083893732728749),
 ('striking', 0.66071190480679143),
 ('tricks', 0.66071190480679143),
 ('carefully', 0.65999497324304479),
 ('complicated', 0.65981076029235353),
 ('perspective', 0.65962448852130173),
 ('trilogy', 0.65877953705573755),
 ('future', 0.65834665141052828),
 ('lion', 0.65742909795786608),
 ('victor', 0.65540685257709819),
 ('douglas', 0.65540685257709819),
 ('inspired', 0.65459851044271034),
 ('marriage', 0.65392646740666405),
 ('demands', 0.65392646740666405),
 ('father', 0.65172321672194655),
 ('page', 0.65123628494430852),
 ('instant', 0.65058756614114943),
 ('era', 0.6495567444850836),
 ('saga', 0.64934455790155243),
 ('ruthless', 0.64934455790155243),
 ('joan', 0.64891392558311978),
 ('joseph', 0.64841128671855386),
 ('workers', 0.64829661439459352),
 ('fantasy', 0.64726757480925168),
 ('distant', 0.64551913157069074),
 ('accomplished', 0.64551913157069074),
 ('manhattan', 0.64435701639051324),
 ('personal', 0.64355023942057321),
 ('individual', 0.64313675998528386),
 ('meeting', 0.64313675998528386),
 ('pushing', 0.64313675998528386),
 ('pleasant', 0.64250344774119039),
 ('brave', 0.64185388617239469),
 ('william', 0.64083139119578469),
 ('hudson', 0.64077919504262937),
 ('friendly', 0.63949446706762514),
 ('eccentric', 0.63907995928966954),
 ('awards', 0.63875310849414646),
 ('jack', 0.63838309514997038),
 ('seeking', 0.63808740337691783),
 ('divorce', 0.63757732940513456),
 ('colonel', 0.63757732940513456),
 ('jane', 0.63443957973316734),
 ('keeping', 0.63414883979798953),
 ('gives', 0.63383568159497883),
 ('ted', 0.63342794585832296),
 ('animation', 0.63208692379869902),
 ('progress', 0.6317782341836532),
 ('larger', 0.63127177684185776),
 ('concert', 0.63127177684185776),
 ('nation', 0.6296337748376194),
 ('albeit', 0.62739580299716491),
 ('adapted', 0.62613647027698516),
 ('discovers', 0.62542900650499444),
 ('classic', 0.62504956428050518),
 ('segment', 0.62335141862440335),
 ('morgan', 0.62303761437291871),
 ('mouse', 0.62294292188669675),
 ('impressive', 0.62211140744319349),
 ('artist', 0.62168821657780038),
 ('ultimate', 0.62168821657780038),
 ('griffith', 0.62117368093485603),
 ('drew', 0.62082651898031915),
 ('emily', 0.62082651898031915),
 ('moved', 0.6197197120051281),
 ('profound', 0.61903920840622351),
 ('families', 0.61903920840622351),
 ('innocent', 0.61851219917136446),
 ('versions', 0.61730910416844087),
 ('eddie', 0.61691981517206107),
 ('criticism', 0.61651395453902935),
 ('nature', 0.61594514653194088),
 ('recognized', 0.61518563909023349),
 ('sexuality', 0.61467556511845012),
 ('contract', 0.61400986000122149),
 ('brian', 0.61344043794920278),
 ('remembered', 0.6131044728864089),
 ('determined', 0.6123858239154869),
 ('offers', 0.61207935747116349),
 ('pleasure', 0.61195702582993206),
 ('washington', 0.61180154110599294),
 ('images', 0.61159731359583758),
 ('games', 0.61067095873570676),
 ('academy', 0.60872983874736208),
 ('fashioned', 0.60798937221963845),
 ('melodrama', 0.60749173598145145),
 ('peoples', 0.60613580357031549),
 ('charismatic', 0.60613580357031549),
 ('rough', 0.60613580357031549),
 ('dealing', 0.60517840761398811),
 ('fine', 0.60496962268013299),
 ('tap', 0.60391604683200273),
 ('trio', 0.60157998703445481),
 ('russell', 0.60120968523425966),
 ('figures', 0.60077386042893011),
 ('ward', 0.60005675749393339),
 ('brady', 0.59911823091166894),
 ('shine', 0.59911823091166894),
 ('job', 0.59845562125168661),
 ('satisfied', 0.59652034487087369),
 ('river', 0.59637962862495086),
 ('brown', 0.595773016534769),
 ('believable', 0.59566072133302495),
 ('always', 0.59470710774669278),
 ('bound', 0.59470710774669278),
 ('hall', 0.5933967777928858),
 ('cook', 0.5916777203950857),
 ('claire', 0.59136448625000293),
 ('broadway', 0.59033768669372433),
 ('anna', 0.58778666490211906),
 ('peace', 0.58628403501758408),
 ('visually', 0.58539431926349916),
 ('falk', 0.58525821854876026),
 ('morality', 0.58525821854876026),
 ('growing', 0.58466653756587539),
 ('stood', 0.58314628534561685),
 ('experiences', 0.58314628534561685),
 ('touch', 0.58122926435596001),
 ('lives', 0.5810976767513224),
 ('kubrick', 0.58066919713325493),
 ('timing', 0.58047401805583243),
 ('expressions', 0.57981849525294216),
 ('struggles', 0.57981849525294216),
 ('authentic', 0.57848427223980559),
 ('helen', 0.57763429343810091),
 ('pre', 0.57700753064729182),
 ('quirky', 0.5753641449035618),
 ('young', 0.57531672344534313),
 ('inner', 0.57454143815209846),
 ('mexico', 0.57443087372056334),
 ('clint', 0.57380042292737909),
 ('sisters', 0.57286101468544337),
 ('realism', 0.57226528899949558),
 ('personalities', 0.5720692490067093),
 ('french', 0.5720692490067093),
 ('adventures', 0.57113222999698177),
 ('surprises', 0.57113222999698177),
 ('overcome', 0.5697681593994407),
 ('timothy', 0.56953322459276867),
 ('tales', 0.56909453188996639),
 ('war', 0.56843317302781682),
 ('civil', 0.5679840376059393),
 ('countries', 0.56737779327091187),
 ('streep', 0.56710645966458029),
 ('tradition', 0.56685345523565323),
 ('oliver', 0.56673325570428668),
 ('australia', 0.56580775818334383),
 ('understanding', 0.56531380905006046),
 ('players', 0.56509525370004821),
 ('knowing', 0.56489284503626647),
 ('rogers', 0.56421349718405212),
 ('suspenseful', 0.56368911332305849),
 ('variety', 0.56368911332305849),
 ('true', 0.56281525180810066),
 ('jr', 0.56220982311246936),
 ('psychological', 0.56108745854687891),
 ('odds', 0.55961578793542266),
 ('performing', 0.55961578793542266),
 ('grand', 0.55961578793542266),
 ('sent', 0.55961578793542266),
 ('wealth', 0.55961578793542266),
 ('overwhelming', 0.55961578793542266),
 ('branagh', 0.55961578793542266),
 ('reminiscent', 0.55961578793542266),
 ('brothers', 0.55891181043362848),
 ('howard', 0.55811089675600245),
 ('david', 0.55693122256475369),
 ('generation', 0.55628799784274796),
 ('grow', 0.55612538299565417),
 ('survival', 0.55594605904646033),
 ('mainstream', 0.55574731115750231),
 ('dick', 0.55431073570572953),
 ('charm', 0.55288175575407861),
 ('kirk', 0.55278982286502287),
 ('twists', 0.55244729845681018),
 ('gangster', 0.55206858230003986),
 ('jeff', 0.55179306225421365),
 ('family', 0.55116244510065526),
 ('tend', 0.55053307336110335),
 ('thanks', 0.55049088015842218),
 ('world', 0.54744234723432639),
 ('sutherland', 0.54743536937855164),
 ('life', 0.54695514434959924),
 ('bug', 0.54654370636806993),
 ('disc', 0.54654370636806993),
 ('tribute', 0.5455111817538808),
 ('europe', 0.54522705048332309),
 ('sacrifice', 0.54430155296238014),
 ('color', 0.54405127139431109),
 ('superior', 0.54333490233128523),
 ('york', 0.54318235866536513),
 ('pulls', 0.54266622962164945),
 ('jackson', 0.54232429082536171),
 ('hearts', 0.54232429082536171),
 ('enjoy', 0.54124285135906114),
 ('redemption', 0.54056759296472823),
 ('madness', 0.540384426007535),
 ('trial', 0.5389965007326869),
 ('greek', 0.5389965007326869),
 ('hamilton', 0.5389965007326869),
 ('stands', 0.5389965007326869),
 ('each', 0.5388212312554177),
 ('faithful', 0.53773307668591508),
 ('received', 0.5372768098531604),
 ('jealous', 0.53714293208336406),
 ('documentaries', 0.53714293208336406),
 ('different', 0.53709860682460819),
 ('describes', 0.53680111016925136),
 ('shorts', 0.53596159703753288),
 ('brilliance', 0.53551823635636209),
 ('mountains', 0.53492317534505118),
 ('share', 0.53408248593025787),
 ('dealt', 0.53408248593025787),
 ('explore', 0.53329847961804933),
 ('providing', 0.53329847961804933),
 ('series', 0.5325809226575603),
 ('fellow', 0.5323318289869543),
 ('olivier', 0.53062825106217038),
 ('roman', 0.53062825106217038),
 ('revolution', 0.53062825106217038),
 ('loves', 0.53062825106217038),
 ('century', 0.53002783074992665),
 ('musical', 0.52966871156747064),
 ('heroic', 0.52925932545482868),
 ('ironically', 0.52806743020049673),
 ('temple', 0.52806743020049673),
 ('approach', 0.52806743020049673),
 ('moves', 0.5279372642387119),
 ('gift', 0.52702030968597136),
 ('julie', 0.52609309589677911),
 ('tells', 0.52415107836314001),
 ('radio', 0.52394671172868779),
 ('uncle', 0.52354439617376536),
 ('union', 0.52324814376454787),
 ('deep', 0.52309571635780505),
 ('reminds', 0.52157841554225237),
 ('famous', 0.52118841080153722),
 ('jazz', 0.52053443789295151),
 ('dennis', 0.51987545928590861),
 ('epic', 0.51919387343650736),
 ('adult', 0.519167695083386),
 ('shows', 0.51915322220375304),
 ('performed', 0.5191244265806858),
 ('demons', 0.5191244265806858),
 ('eric', 0.51879379341516751),
 ('discovered', 0.51879379341516751),
 ('youth', 0.5185626062681431),
 ('human', 0.51851411224987087),
 ('tarzan', 0.51813827061227724),
 ('ourselves', 0.51794309153485463),
 ('wwii', 0.51758240622887042),
 ('passion', 0.5162164724008671),
 ('desire', 0.51607497965213445),
 ('pays', 0.51581316527702981),
 ('dirty', 0.51557622652458857),
 ('fox', 0.51557622652458857),
 ('sympathetic', 0.51546600332249293),
 ('symbolism', 0.51546600332249293),
 ('attitude', 0.51530993621331933),
 ('appearances', 0.51466440007315639),
 ('jeremy', 0.51466440007315639),
 ('fun', 0.51439068993048687),
 ('south', 0.51420972175023116),
 ('arrives', 0.51409894911095988),
 ('present', 0.51341965894303732),
 ('com', 0.51326167856387173),
 ('smile', 0.51265880484765169),
 ('provided', 0.51082562376599072),
 ('carter', 0.51082562376599072),
 ('alan', 0.51082562376599072),
 ('countryside', 0.51082562376599072),
 ('aging', 0.51082562376599072),
 ('ring', 0.51082562376599072),
 ('visit', 0.51082562376599072),
 ('fits', 0.51082562376599072),
 ('begins', 0.51015650363396647),
 ('japan', 0.50900578704900468),
 ('success', 0.50900578704900468),
 ('accurate', 0.50895471583017893),
 ('proud', 0.50800474742434931),
 ('daily', 0.5075946031845443),
 ('atmospheric', 0.50724780241810674),
 ('karloff', 0.50724780241810674),
 ('recently', 0.50714914903668207),
 ('fu', 0.50704490092608467),
 ('horrors', 0.50656122497953315),
 ('finding', 0.50637127341661037),
 ('lust', 0.5059356384717989),
 ('hitchcock', 0.50574947073413001),
 ('among', 0.50334004951332734),
 ('viewing', 0.50302139827440906),
 ('shining', 0.50262885656181222),
 ('investigation', 0.50262885656181222),
 ('cameron', 0.5020919437972361),
 ('duo', 0.5020919437972361),
 ('finds', 0.50128303100539795),
 ('contemporary', 0.50077528791248915),
 ('genuine', 0.50046283673044401),
 ('frightening', 0.49995595152908684),
 ('plays', 0.49975983848890226),
 ('age', 0.49941323171424595),
 ('position', 0.49899116611898781),
 ('continues', 0.49863035067217237),
 ('roles', 0.49839716550752178),
 ('james', 0.49837216269470402),
 ('individuals', 0.49824684155913052),
 ('brought', 0.49783842823917956),
 ('hilarious', 0.49714551986191058),
 ('brutal', 0.49681488669639234),
 ('appropriate', 0.49643688631389105),
 ('dance', 0.49581998314812048),
 ('league', 0.49578774640145024),
 ('helping', 0.49578774640145024),
 ('answers', 0.49578774640145024),
 ('stunts', 0.49561620510246196),
 ('traveling', 0.49532143723002542),
 ('thoroughly', 0.49414593456733524),
 ('depicted', 0.49317068852726992),
 ('differences', 0.49247648509779424),
 ('honor', 0.49247648509779424),
 ('combination', 0.49247648509779424),
 ('fully', 0.49213349075383811),
 ('tracy', 0.49159426183810306),
 ('battles', 0.49140753790888908),
 ('possibility', 0.49112055268665822),
 ('romance', 0.4901589869574316),
 ('initially', 0.49002249613622745),
 ('happy', 0.4898997500608791),
 ('crime', 0.48977221456815834),
 ('singing', 0.4893852925281213),
 ('especially', 0.48901267837860624),
 ('shakespeare', 0.48754793889664511),
 ('hugh', 0.48729512635579658),
 ('detail', 0.48609484250827351),
 ('desperation', 0.48550781578170082),
 ('julia', 0.48550781578170082),
 ('san', 0.48550781578170082),
 ('companion', 0.48550781578170082),
 ('guide', 0.48550781578170082),
 ('strongly', 0.48460242866688824),
 ('necessary', 0.48302334245403883),
 ('humanity', 0.48265474679929443),
 ('drama', 0.48221998493060503),
 ('warming', 0.48183808689273838),
 ('intrigue', 0.48183808689273838),
 ('nonetheless', 0.48183808689273838),
 ('cuba', 0.48183808689273838),
 ('planned', 0.47957308026188628),
 ('pictures', 0.47929937011921681),
 ('broadcast', 0.47849024312305422),
 ('nine', 0.47803580094299974),
 ('settings', 0.47743860773325364),
 ('history', 0.47732966933780852),
 ('ordinary', 0.47725880012690741),
 ('trade', 0.47692407209030935),
 ('primary', 0.47608267532211779),
 ('official', 0.47608267532211779),
 ('episode', 0.47529620261150429),
 ('role', 0.47520268270188676),
 ('spirit', 0.47477690799839323),
 ('grey', 0.47409361449726067),
 ('ways', 0.47323464982718205),
 ('piano', 0.47260441094579297),
 ('cup', 0.47260441094579297),
 ('familiar', 0.47241617565111949),
 ('sinister', 0.47198579044972683),
 ('reveal', 0.47171449364936496),
 ('max', 0.47150852042515579),
 ('dated', 0.47121648567094482),
 ('discovery', 0.47000362924573563),
 ('losing', 0.47000362924573563),
 ('vicious', 0.47000362924573563),
 ('genuinely', 0.46871413841586385),
 ('hatred', 0.46734051182625186),
 ('mistaken', 0.46702300110759781),
 ('challenge', 0.46608972992459924),
 ('dream', 0.46608972992459924),
 ('crisis', 0.46575733836428446),
 ('photographed', 0.46488852857896512),
 ('machines', 0.46430560813109778),
 ('critics', 0.46430560813109778),
 ('bird', 0.46430560813109778),
 ('born', 0.46411383518967209),
 ('detective', 0.4636633473511525),
 ('higher', 0.46328467899699055),
 ('inevitable', 0.46262352194811296),
 ('remains', 0.46262352194811296),
 ('soviet', 0.4618180446592961),
 ('ryan', 0.46134556650262099),
 ('african', 0.46112595521371813),
 ('smaller', 0.46081520319132935),
 ('techniques', 0.46052488529119184),
 ('information', 0.46034171833399862),
 ('deserved', 0.45999798712841444),
 ('spielberg', 0.45953232937844013),
 ('francisco', 0.45953232937844013),
 ('tour', 0.45953232937844013),
 ('lynch', 0.45953232937844013),
 ('cynical', 0.45953232937844013),
 ('struggle', 0.45911782160048453),
 ('language', 0.45902121257712653),
 ('visual', 0.45823514408822852),
 ('warner', 0.45724137763188427),
 ('social', 0.45720078250735313),
 ('reality', 0.45719346885019546),
 ('hidden', 0.45675840249571492),
 ('breaking', 0.45601738727099561),
 ('sometimes', 0.45563021171182794),
 ('modern', 0.45500247579345005),
 ('surfing', 0.45425527227759638),
 ('popular', 0.45410691533051023),
 ('surprised', 0.4534409399850382),
 ('follows', 0.45245361754408348),
 ('keeps', 0.45234869400701483),
 ('john', 0.4520909494482197),
 ('defeat', 0.45198512374305722),
 ('mixed', 0.45198512374305722),
 ('justice', 0.45142724367280018),
 ('treasure', 0.45083371313801535),
 ('presents', 0.44973793178615257),
 ('years', 0.44919197032104968),
 ('chief', 0.44895022004790319),
 ('shadows', 0.44802472252696035),
 ('segments', 0.44701411102103689),
 ('closely', 0.44701411102103689),
 ('lose', 0.44658335503763702),
 ('caine', 0.44628710262841953),
 ('caught', 0.44610275383999071),
 ('hamlet', 0.44558510189758965),
 ('chinese', 0.44507424620321018),
 ('welcome', 0.44438052435783792),
 ('birth', 0.44368632092836219),
 ('represents', 0.44320543609101143),
 ('puts', 0.44279106572085081),
 ('closer', 0.44183275227903923),
 ('web', 0.44183275227903923),
 ('fame', 0.44183275227903923),
 ('visuals', 0.44183275227903923),
 ('criminal', 0.4412745608048752),
 ('minor', 0.4409224199448939),
 ('jon', 0.44086703515908027),
 ('liked', 0.44074991514020723),
 ('restaurant', 0.44031183943833246),
 ('flaws', 0.43983275161237217),
 ('de', 0.43983275161237217),
 ('searching', 0.4393666597838457),
 ('rap', 0.43891304217570443),
 ('light', 0.43884433018199892),
 ('elizabeth', 0.43872232986464677),
 ('marry', 0.43861731542506488),
 ('learned', 0.43825493093115531),
 ('controversial', 0.43825493093115531),
 ('oz', 0.43825493093115531),
 ('slowly', 0.43785660389939979),
 ('comedic', 0.43721380642274466),
 ('bridge', 0.43721380642274466),
 ('thrilling', 0.43721380642274466),
 ('wayne', 0.43721380642274466),
 ('married', 0.43658501682196887),
 ('nazi', 0.4361020775700542),
 ('physical', 0.4353180712578455),
 ('murder', 0.4353180712578455),
 ('johnny', 0.43483971678806865),
 ('michelle', 0.43445264498141672),
 ('wallace', 0.43403848055222038),
 ('comedies', 0.43395706390247063),
 ('silent', 0.43395706390247063),
 ('played', 0.43387244114515305),
 ('international', 0.43363598507486073),
 ('vision', 0.43286408229627887),
 ('intelligent', 0.43196704885367099),
 ('shop', 0.43078291609245434),
 ('also', 0.43036720209769169),
 ('levels', 0.4302451371066513),
 ('miss', 0.43006426712153217),
 ('revolutionary', 0.4295626596872249),
 ...]

In [151]:
# words most frequently seen in a review with a "NEGATIVE" label
list(reversed(pos_neg_ratios.most_common()))[0:30]


Out[151]:
[('boll', -4.9698132995760007),
 ('uwe', -4.6249728132842707),
 ('seagal', -3.6441435602725449),
 ('unwatchable', -3.2580965380214821),
 ('stinker', -3.208825489014699),
 ('mst', -2.9502698994772336),
 ('incoherent', -2.9368917735310576),
 ('unfunny', -2.6922395950755678),
 ('waste', -2.6193845640165541),
 ('blah', -2.5704288232261625),
 ('horrid', -2.4849066497880004),
 ('pointless', -2.4553061800117097),
 ('atrocious', -2.4259083090260445),
 ('redeeming', -2.3682390632154826),
 ('prom', -2.3608540011180215),
 ('drivel', -2.3470368555648795),
 ('lousy', -2.3075726345050844),
 ('worst', -2.2869878961803778),
 ('laughable', -2.2643638801738479),
 ('awful', -2.2271942470274348),
 ('poorly', -2.2207550747464135),
 ('wasting', -2.2046046846338418),
 ('remotely', -2.1972245773362196),
 ('existent', -2.0794415416798357),
 ('boredom', -1.9951003932460849),
 ('miserably', -1.9924301646902063),
 ('sucks', -1.9870682215488209),
 ('uninspired', -1.9832976811269336),
 ('lame', -1.981767458946166),
 ('insult', -1.9783454248084671)]

In [7]:
from bokeh.models import ColumnDataSource, LabelSet
from bokeh.plotting import figure, show, output_file
from bokeh.io import output_notebook
output_notebook()


Loading BokehJS ...

In [158]:
hist, edges = np.histogram(list(map(lambda x:x[1],pos_neg_ratios.most_common())), density=True, bins=100, normed=True)

p = figure(tools="pan,wheel_zoom,reset,save",
           toolbar_location="above",
           title="Word Positive/Negative Affinity Distribution")
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="#555555")
show(p)


Loading BokehJS ...

In this graph "0" means that a word has no affinitity for either positive or negative. AS you can see, the vast majority of our words don't have that much direct affinity! So, our network is having to learn about lots of terms that are likely irrelevant to the final prediction. If we remove some of the most irrelevant words, our network will have fewer words that it has to learn about, allowing it to focus more on the words that matters.

Furthermore, check out this graph of simple word frequency


In [236]:
frequency_frequency = Counter()

for word, cnt in total_counts.most_common():
    frequency_frequency[cnt] += 1

In [239]:
hist, edges = np.histogram(list(map(lambda x:x[1],frequency_frequency.most_common())), density=True, bins=100, normed=True)

p = figure(tools="pan,wheel_zoom,reset,save",
           toolbar_location="above",
           title="The frequency distribution of the words in our corpus")
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="#555555")
show(p)


As you can see, the vast majority of words in our corpus only happen once or twice. Unfortunately, this isn't enough for any of those words to be correlated with anything. Correlation requires seeing two things occur at the same time on multiple occasions so that you can identify a pattern. We should eliminate these very low frequency terms as well.

In the next network, we eliminate both low frequency words (via a min_count parameters) and words with low positive/negative affiliation


In [18]:
import time
import sys
import numpy as np

# Let's tweak our network from before to model these phenomena
class SentimentNetwork:
    def __init__(self, reviews,labels,min_count = 10,polarity_cutoff = 0.1,hidden_nodes = 10, learning_rate = 0.1):
       
        np.random.seed(1)
    
        self.pre_process_data(reviews, polarity_cutoff, min_count)
        
        self.init_network(len(self.review_vocab),hidden_nodes, 1, learning_rate)
        
        
    def pre_process_data(self,reviews, polarity_cutoff,min_count):
        
        positive_counts = Counter()
        negative_counts = Counter()
        total_counts = Counter()

        for i in range(len(reviews)):
            if(labels[i] == 'POSITIVE'):
                for word in reviews[i].split(" "):
                    positive_counts[word] += 1
                    total_counts[word] += 1
            else:
                for word in reviews[i].split(" "):
                    negative_counts[word] += 1
                    total_counts[word] += 1

        pos_neg_ratios = Counter()

        for term,cnt in list(total_counts.most_common()):
            if(cnt >= 50):
                pos_neg_ratio = positive_counts[term] / float(negative_counts[term]+1)
                pos_neg_ratios[term] = pos_neg_ratio

        for word,ratio in pos_neg_ratios.most_common():
            if(ratio > 1):
                pos_neg_ratios[word] = np.log(ratio)
            else:
                pos_neg_ratios[word] = -np.log((1 / (ratio + 0.01)))
        
        review_vocab = set()
        for review in reviews:
            for word in review.split(" "):
                if(total_counts[word] > min_count):
                    if(word in pos_neg_ratios.keys()):
                        if((pos_neg_ratios[word] >= polarity_cutoff) or (pos_neg_ratios[word] <= -polarity_cutoff)):
                            review_vocab.add(word)
                    else:
                        review_vocab.add(word)
        self.review_vocab = list(review_vocab)
        
        label_vocab = set()
        for label in labels:
            label_vocab.add(label)
        
        self.label_vocab = list(label_vocab)
        
        self.review_vocab_size = len(self.review_vocab)
        self.label_vocab_size = len(self.label_vocab)
        
        self.word2index = {}
        for i, word in enumerate(self.review_vocab):
            self.word2index[word] = i
        
        self.label2index = {}
        for i, label in enumerate(self.label_vocab):
            self.label2index[label] = i
         
        
    def init_network(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
        # Set number of nodes in input, hidden and output layers.
        self.input_nodes = input_nodes
        self.hidden_nodes = hidden_nodes
        self.output_nodes = output_nodes

        # Initialize weights
        self.weights_0_1 = np.zeros((self.input_nodes,self.hidden_nodes))
    
        self.weights_1_2 = np.random.normal(0.0, self.output_nodes**-0.5, 
                                                (self.hidden_nodes, self.output_nodes))
        
        self.learning_rate = learning_rate
        
        self.layer_0 = np.zeros((1,input_nodes))
        self.layer_1 = np.zeros((1,hidden_nodes))
        
    def sigmoid(self,x):
        return 1 / (1 + np.exp(-x))
    
    
    def sigmoid_output_2_derivative(self,output):
        return output * (1 - output)
    
    def update_input_layer(self,review):

        # clear out previous state, reset the layer to be all 0s
        self.layer_0 *= 0
        for word in review.split(" "):
            self.layer_0[0][self.word2index[word]] = 1

    def get_target_for_label(self,label):
        if(label == 'POSITIVE'):
            return 1
        else:
            return 0
        
    def train(self, training_reviews_raw, training_labels):
        
        training_reviews = list()
        for review in training_reviews_raw:
            indices = set()
            for word in review.split(" "):
                if(word in self.word2index.keys()):
                    indices.add(self.word2index[word])
            training_reviews.append(list(indices))
        
        assert(len(training_reviews) == len(training_labels))
        
        correct_so_far = 0
        
        start = time.time()
        
        for i in range(len(training_reviews)):
            
            review = training_reviews[i]
            label = training_labels[i]
            
            #### Implement the forward pass here ####
            ### Forward pass ###

            # Input Layer

            # Hidden layer
#             layer_1 = self.layer_0.dot(self.weights_0_1)
            self.layer_1 *= 0
            for index in review:
                self.layer_1 += self.weights_0_1[index]
            
            # Output layer
            layer_2 = self.sigmoid(self.layer_1.dot(self.weights_1_2))

            #### Implement the backward pass here ####
            ### Backward pass ###

            # Output error
            layer_2_error = layer_2 - self.get_target_for_label(label) # Output layer error is the difference between desired target and actual output.
            layer_2_delta = layer_2_error * self.sigmoid_output_2_derivative(layer_2)

            # Backpropagated error
            layer_1_error = layer_2_delta.dot(self.weights_1_2.T) # errors propagated to the hidden layer
            layer_1_delta = layer_1_error # hidden layer gradients - no nonlinearity so it's the same as the error

            # Update the weights
            self.weights_1_2 -= self.layer_1.T.dot(layer_2_delta) * self.learning_rate # update hidden-to-output weights with gradient descent step
            
            for index in review:
                self.weights_0_1[index] -= layer_1_delta[0] * self.learning_rate # update input-to-hidden weights with gradient descent step

            if(layer_2 >= 0.5 and label == 'POSITIVE'):
                correct_so_far += 1
            if(layer_2 < 0.5 and label == 'NEGATIVE'):
                correct_so_far += 1
            
            reviews_per_second = i / float(time.time() - start)
            
            sys.stdout.write("\rProgress:" + str(100 * i/float(len(training_reviews)))[:4] + "% Speed(reviews/sec):" + str(reviews_per_second)[0:5] + " #Correct:" + str(correct_so_far) + " #Trained:" + str(i+1) + " Training Accuracy:" + str(correct_so_far * 100 / float(i+1))[:4] + "%")
        
    
    def test(self, testing_reviews, testing_labels):
        
        correct = 0
        
        start = time.time()
        
        for i in range(len(testing_reviews)):
            pred = self.run(testing_reviews[i])
            if(pred == testing_labels[i]):
                correct += 1
            
            reviews_per_second = i / float(time.time() - start)
            
            sys.stdout.write("\rProgress:" + str(100 * i/float(len(testing_reviews)))[:4] \
                             + "% Speed(reviews/sec):" + str(reviews_per_second)[0:5] \
                            + "% #Correct:" + str(correct) + " #Tested:" + str(i+1) + " Testing Accuracy:" + str(correct * 100 / float(i+1))[:4] + "%")
    
    def run(self, review):
        
        # Input Layer


        # Hidden layer
        self.layer_1 *= 0
        unique_indices = set()
        for word in review.lower().split(" "):
            if word in self.word2index.keys():
                unique_indices.add(self.word2index[word])
        for index in unique_indices:
            self.layer_1 += self.weights_0_1[index]
        
        # Output layer
        layer_2 = self.sigmoid(self.layer_1.dot(self.weights_1_2))
        
        if(layer_2[0] >= 0.5):
            return "POSITIVE"
        else:
            return "NEGATIVE"

In [6]:
mlp = SentimentNetwork(reviews[:-1000],labels[:-1000],min_count=20,polarity_cutoff=0.05,learning_rate=0.01)

In [7]:
mlp.train(reviews[:-1000],labels[:-1000])


Progress:99.9% Speed(reviews/sec):1274. #Correct:20461 #Trained:24000 Training Accuracy:85.2%

In [8]:
mlp.test(reviews[-1000:],labels[-1000:])


Progress:99.9% Speed(reviews/sec):1669.% #Correct:859 #Tested:1000 Testing Accuracy:85.9%

So, using these techniques, we are able to achieve a slightly higher testing score while training 2x faster than before. Furthermore, if we really crank up these metrics, we can get some pretty extreme speed with minimal loss in quality (if, for example, your business use case requires running very fast)


In [52]:
mlp = SentimentNetwork(reviews[:-1000],labels[:-1000],min_count=20,polarity_cutoff=0.8,learning_rate=0.01)

In [53]:
mlp.train(reviews[:-1000],labels[:-1000])


Progress:99.9% Speed(reviews/sec):9716. #Correct:20552 #Trained:24000 Training Accuracy:85.6%

In [55]:
mlp.test(reviews[-1000:],labels[-1000:])


Progress:99.9% Speed(reviews/sec):5347.% #Correct:822 #Tested:1000 Testing Accuracy:82.2%

What's Going On in the Weights?


In [19]:
mlp = SentimentNetwork(reviews[:-1000],labels[:-1000],min_count=0,polarity_cutoff=0,learning_rate=0.01)

In [20]:
mlp.train(reviews[:-1000],labels[:-1000])


Progress:99.9% Speed(reviews/sec):1020. #Correct:20335 #Trained:24000 Training Accuracy:84.7%

In [12]:
import matplotlib.colors as colors

In [23]:
words_to_visualize = list()
for word, ratio in pos_neg_ratios.most_common(500):
    if(word in mlp.word2index.keys()):
        words_to_visualize.append(word)
    
for word, ratio in list(reversed(pos_neg_ratios.most_common()))[0:500]:
    if(word in mlp.word2index.keys()):
        words_to_visualize.append(word)

In [42]:
colors_list = list()
vectors_list = list()
for word in words_to_visualize:
    if word in pos_neg_ratios.keys():
        vectors_list.append(mlp.weights_0_1[mlp.word2index[word]])
        if(pos_neg_ratios[word] > 0):

            colors_list.append("#"+colors.rgb2hex([0,min(255,pos_neg_ratios[word] * 1),0])[3:])
        else:
            colors_list.append("#000000")
#             colors_list.append("#"+colors.rgb2hex([0,0,min(255,pos_neg_ratios[word] * 1)])[3:])

In [36]:
from sklearn.manifold import TSNE
tsne = TSNE(n_components=2, random_state=0)
words_top_ted_tsne = tsne.fit_transform(vectors_list)

In [45]:
p = figure(tools="pan,wheel_zoom,reset,save",
           toolbar_location="above",
           title="vector T-SNE for most polarized words")

source = ColumnDataSource(data=dict(x1=words_top_ted_tsne[:,0],
                                    x2=words_top_ted_tsne[:,1],
                                    names=words_to_visualize))

p.scatter(x="x1", y="x2", size=8, source=source,color=colors_list)

word_labels = LabelSet(x="x1", y="x2", text="names", y_offset=6,
                  text_font_size="8pt", text_color="#555555",
                  source=source, text_align='center')
# p.add_layout(word_labels)

show(p)

# green indicates positive words, black indicates negative words



In [ ]: